Class: SimpleSysLogger::SysLogger
- Inherits:
-
Object
- Object
- SimpleSysLogger::SysLogger
- Defined in:
- lib/simplesyslogger.rb
Constant Summary collapse
- MAPPING =
{ Logger::DEBUG => "debug", Logger::INFO => "info", Logger::WARN => "warning", Logger::ERROR => "err", Logger::FATAL => "crit", Logger::UNKNOWN => "alert" }
Instance Attribute Summary collapse
-
#facility ⇒ Object
readonly
Returns the value of attribute facility.
-
#ident ⇒ Object
readonly
Returns the value of attribute ident.
-
#level ⇒ Object
Returns the value of attribute level.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Low level method to add a message.
-
#initialize(opts = {}) ⇒ SysLogger
constructor
A new instance of SysLogger.
Constructor Details
#initialize(opts = {}) ⇒ SysLogger
Returns a new instance of SysLogger.
20 21 22 23 24 25 |
# File 'lib/simplesyslogger.rb', line 20 def initialize(opts = {}) @ident = opts[:ident] || $0 @options = opts[:options] || (Syslog::LOG_PID | Syslog::LOG_CONS) @level = opts[:level]|| Logger::INFO @facility = opts[:facility] || Syslog::LOG_LOCAL0 end |
Instance Attribute Details
#facility ⇒ Object (readonly)
Returns the value of attribute facility.
9 10 11 |
# File 'lib/simplesyslogger.rb', line 9 def facility @facility end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
9 10 11 |
# File 'lib/simplesyslogger.rb', line 9 def ident @ident end |
#level ⇒ Object
Returns the value of attribute level.
9 10 11 |
# File 'lib/simplesyslogger.rb', line 9 def level @level end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/simplesyslogger.rb', line 9 def @options end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Low level method to add a message.
severity
-
the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
message
-
the message string. If nil, the method will call the block and use the result as the message string. If both are nil or no block is given, it will use the progname as per the behaviour of both the standard Ruby logger, and the Rails BufferedLogger.
progname
-
optionally, overwrite the program name that appears in the log message.
59 60 61 62 63 64 65 66 |
# File 'lib/simplesyslogger.rb', line 59 def add(severity, = nil, progname = nil, &block) formatted_communication = "=====> #{MAPPING[severity]} :::: #{}" Syslog.open(progname || @ident, @options) { |s| puts "#{MAPPING[severity]} ..... logger:::: #{formatted_communication}" #s.warning "logger:::: #{formatted_communication}" s.send("#{MAPPING[severity]}".to_sym, formatted_communication) } end |