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!

Methods

<<   add   add_with_formatting   new   silence  

Included Modules

Logger::Severity

Constants

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

Attributes

level  [RW]  Log level for Logger compatibility.

Public Class methods

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.

[Source]

    # 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

Public Instance methods

In Logger, this dumps the raw message; the closest equivalent would be Logger::UNKNOWN

[Source]

     # File lib/syslog_logger.rb, line 102
102:   def <<(message)
103:     add(Logger::UNKNOWN, message)
104:   end

Almost duplicates Logger#add. progname is ignored.

[Source]

    # 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

[Source]

    # 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

Allows messages of a particular log level to be ignored temporarily.

[Source]

    # File lib/syslog_logger.rb, line 92
92:   def silence(temporary_level = Logger::ERROR)
93:     old_logger_level = @level
94:     @level = temporary_level
95:     yield
96:   ensure
97:     @level = old_logger_level
98:   end

[Validate]