Object
Adds some default information to syslog messages. If you pass a User or Device object as the first parameter, it will log that user/device’s id If you pass a block from a controller, it will automatically log the current user id If you pass a block, the class name of the block’s context will be added
Examples logger.debug “O’Doyle Rules!”
#=> [development] [DEBUG: 2008-01-25 14:16:12.12345] O'Doyle Rules!
from within a controller… logger.error {“Something is messed up!”}
#=> [development] [ERROR: 2008-01-25 14:16:12.12345] [123] [ClassName] Something is messed up!
Maps Logger log level values to syslog log levels.
Maps Logger log levels to their values so we can silence.
Maps Logger warning types to syslog(3) warning types.
The version of SyslogLogger you are using.
Fills in variables for Logger compatibility. If this is the first instance of SyslogLogger, program_name may be set to change the logged program name and facility may be set to specify a custom facility with your syslog daemon.
Due to the way syslog works, only one program name may be chosen.
# File lib/syslog_logger.rb, line 73 def initialize(program_name = 'rails', facility = Syslog::LOG_USER, logopts=nil) @level = Logger::DEBUG return if defined? SYSLOG self.class.const_set :SYSLOG, Syslog.open(program_name, logopts, facility) end
In Logger, this dumps the raw message; the closest equivalent would be Logger::UNKNOWN
# File lib/syslog_logger.rb, line 101 def <<(message) add(Logger::UNKNOWN, message) end
Almost duplicates Logger#add. progname is ignored.
# File lib/syslog_logger.rb, line 81 def add(severity, message = nil, progname = nil, &block) severity ||= Logger::UNKNOWN if severity >= @level message = clean(message || block.call) SYSLOG.send LEVEL_LOGGER_MAP[severity], clean(message) end true end
# File lib/syslog_logger_env_formatting.rb, line 25 def add_with_formatting(severity, message = nil, progname = nil, &block) severity ||= Logger::UNKNOWN message = "[#{RAILS_ENV}] [#{@@log_level_names[severity].ljust(LOG_NAME_FIELD_WIDTH)}: #{time.strftime("%Y-%m-%d %H:%M:%S")}.#{time.usec.to_s.rjust(6, '0')}] #{message}" if(block) add_without_formatting(severity, message, progname, &Proc.new{g_log_formatter(severity, nil, user, &block)}) else add_without_formatting(severity, message, progname) end end
Allows messages of a particular log level to be ignored temporarily.
# File lib/syslog_logger.rb, line 91 def silence(temporary_level = Logger::ERROR) old_logger_level = @level @level = temporary_level yield ensure @level = old_logger_level end
Generated with the Darkfish Rdoc Generator 2.