class SimpleSysLogger::SysLogger
Constants
- MAPPING
Attributes
facility[R]
ident[R]
level[R]
options[R]
Public Class Methods
new(opts = {})
click to toggle source
# 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
Public Instance Methods
add(severity, message = nil, progname = nil, &block)
click to toggle source
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.
# File lib/simplesyslogger.rb, line 59 def add(severity, message = nil, progname = nil, &block) formatted_communication = "=====> #{MAPPING[severity]} :::: #{message}" 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
level=(level)
click to toggle source
Sets the minimum level for messages to be written in the log.
level
-
one of
Logger::DEBUG
,Logger::INFO
,Logger::WARN
,Logger::ERROR
,Logger::FATAL
,Logger::UNKNOWN
# File lib/simplesyslogger.rb, line 45 def level=(level) level = Logger.const_get(level.to_s.upcase) if level.is_a?(Symbol) unless level.is_a?(Fixnum) raise ArgumentError.new("Invalid logger level `#{level.inspect}`") end @level = level end