Class: SimpleSysLogger::Logger
- Inherits:
-
Object
- Object
- SimpleSysLogger::Logger
- 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(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil) ⇒ Logger
Returns a new instance of Logger.
19 20 21 22 23 24 25 |
# File 'lib/simplesyslogger.rb', line 19 def initialize(ident = $0, = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil) puts "initialize syslogger" @ident = ident = || (Syslog::LOG_PID | Syslog::LOG_CONS) @level = Logger::INFO @facility = @facility end |
Instance Attribute Details
#facility ⇒ Object (readonly)
Returns the value of attribute facility.
7 8 9 |
# File 'lib/simplesyslogger.rb', line 7 def facility @facility end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
7 8 9 |
# File 'lib/simplesyslogger.rb', line 7 def ident @ident end |
#level ⇒ Object
Returns the value of attribute level.
7 8 9 |
# File 'lib/simplesyslogger.rb', line 7 def level @level end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/simplesyslogger.rb', line 7 def 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]} :::: #{message}" Syslog.open(progname || @ident, Syslog::LOG_PID | Syslog::LOG_CONS) { |s| puts "#{MAPPING[severity]} ..... logger:::: #{formatted_communication}" #s.warning "logger:::: #{formatted_communication}" s.send("#{MAPPING[severity]}".to_sym, formatted_communication) } end |