Class: CanvasOss::Event::Logger
- Inherits:
-
Object
- Object
- CanvasOss::Event::Logger
- Defined in:
- lib/canvas_oss/event.rb
Overview
Class that log message using syslog
Constant Summary collapse
- FACILITIES =
Table of Syslog facilities constants
[Syslog::LOG_LOCAL0, Syslog::LOG_LOCAL1, Syslog::LOG_LOCAL2, Syslog::LOG_LOCAL3, Syslog::LOG_LOCAL4, Syslog::LOG_LOCAL5, Syslog::LOG_LOCAL6, Syslog::LOG_LOCAL7].freeze
Instance Method Summary collapse
-
#close ⇒ Object
Close connection if there is one opened.
-
#initialize(program_name, facility) ⇒ Logger
constructor
Initialize Syslog::Logger class with a private call to #connect.
-
#log(severity, message) ⇒ Object
Send logs thrue Syslog connection.
Constructor Details
#initialize(program_name, facility) ⇒ Logger
Initialize Syslog::Logger class with a private call to #connect.
37 38 39 |
# File 'lib/canvas_oss/event.rb', line 37 def initialize(program_name, facility) connect(program_name, facility) end |
Instance Method Details
#close ⇒ Object
Close connection if there is one opened. If not, raise error.
71 72 73 74 75 76 77 78 |
# File 'lib/canvas_oss/event.rb', line 71 def close begin Syslog::Logger.syslog.close rescue RuntimeError => exception raise "There is no Syslog connection to close : #{exception}" end return true end |
#log(severity, message) ⇒ Object
Send logs thrue Syslog connection
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/canvas_oss/event.rb', line 47 def log(severity, ) raise ArgumentError, 'Message must be a String' unless .is_a?(String) begin case severity when 'alert' @log.unknown '[Alert] : ' + when 'error' @log.error '[Error] : ' + when 'warn' @log.warn '[Warning] : ' + when 'info' @log.info '[Info] : ' + when 'debug' @log.debug '[Debug] : ' + else raise "You've provided a false severity name. Choose between : alert, error, warn, info, debug." end rescue RuntimeError => exception raise "#{exception}. Syslog opened status : #{Syslog::Logger.syslog.opened?} " end end |