| Class | SyslogLogger |
| In: |
lib/syslog_logger.rb
lib/syslog_logger_env_formatting.rb |
| Parent: | 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!
| VERSION | = | '1.6.1' | The version of SyslogLogger you are using. | |
| LOGGER_MAP | = | { :unknown => :alert, :fatal => :crit, :error => :err, :warn => :warning, :info => :info, :debug => :debug | Maps Logger warning types to syslog(3) warning types. | |
| LOGGER_LEVEL_MAP | = | {} | Maps Logger log levels to their values so we can silence. | |
| LEVEL_LOGGER_MAP | = | {} | Maps Logger log level values to syslog log levels. | |
| LOG_NAME_FIELD_WIDTH | = | 7 |
| level | [RW] | Log level for Logger compatibility. |
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 74
74: def initialize(program_name = 'rails', facility = Syslog::LOG_USER, logopts=nil)
75: @level = Logger::DEBUG
76:
77: return if defined? SYSLOG
78: self.class.const_set :SYSLOG, Syslog.open(program_name, logopts, facility)
79: end
In Logger, this dumps the raw message; the closest equivalent would be Logger::UNKNOWN
# File lib/syslog_logger.rb, line 102
102: def <<(message)
103: add(Logger::UNKNOWN, message)
104: end
Almost duplicates Logger#add. progname is ignored.
# File lib/syslog_logger.rb, line 82
82: def add(severity, message = nil, progname = nil, &block)
83: severity ||= Logger::UNKNOWN
84: if severity >= @level
85: message = clean(message || block.call)
86: SYSLOG.send LEVEL_LOGGER_MAP[severity], clean(message)
87: end
88: true
89: end
# File lib/syslog_logger_env_formatting.rb, line 25
25: def add_with_formatting(severity, message = nil, progname = nil, &block)
26: severity ||= Logger::UNKNOWN
27: 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}"
28:
29: if(block)
30: add_without_formatting(severity, message, progname,
31: &Proc.new{g_log_formatter(severity, nil, user, &block)})
32: else
33: add_without_formatting(severity, message, progname)
34: end
35: end