class Slogger::CommonLogger
It just exposes Ruby's Syslog with the same API of Ruby's standard Logger
class. So you can use it in a Rails application, for instance.
For example, add the snippet below to the config/environments/developement.rb of an Rails application:
config.log_level = :info config.logger = Slogger::CommonLogger.new
“rappils”, config.log_level, :local0
That's all. The Rails application will log everything to the standard syslog.
Constants
- BRIDGE_SEVERITIES
Bridge between standard Ruby
Logger
and Syslog- FACILITIES
Just a little sugar
- SEVERITIES
Attributes
For Rails/ActiveSupport 4 compatibility
Public Class Methods
To build a Slogger::CommonLogger
instance.
app_name
-
The appliaction name to be logged
severity
-
The log severity (according to standard Ruby
Logger
): :unknow, :fatal,:error, :warn, :info, or :debug. It can be changed at anytime.
facility
-
A typical syslog facility: :kernel, :user, :mail, :daemon, :auth,
:syslog, :lpr, :news, :uucp, :cron, :authpriv, :ftp, :local0, :local1, :local2, :local3, :local4, :local5, :local6, or :local7
Raises an ArgumentError if app_name, severity, or facility is nil.
Slogger::Base::new
# File lib/slogger/common_logger.rb, line 60 def initialize(app_name, severity, facility) super app_name, BRIDGE_SEVERITIES[severity], facility, SEVERITIES @formatter = ::Logger::Formatter.new end
Public Instance Methods
# File lib/slogger/common_logger.rb, line 85 def add(severity, message = nil, progname = nil, &block) (BRIDGE_SEVERITIES.keys - [:unknow]).each do |key| if ::Logger.const_get(key.to_s.upcase) == severity return log(BRIDGE_SEVERITIES[key], message, &block) end end log(BRIDGE_SEVERITIES[:unkown], message, &block) end
# File lib/slogger/common_logger.rb, line 73 def level ::Logger.const_get(BRIDGE_SEVERITIES.to_a.rassoc(@severity)[0].to_s.upcase) end
Slogger::Base#log
# File lib/slogger/common_logger.rb, line 65 def log(severity, message = nil, &block) if block_given? and message != nil super(severity, message, &block) else super(severity, (message || (block_given? && block.call) || @app_name), &nil) end end
# File lib/slogger/common_logger.rb, line 77 def severity BRIDGE_SEVERITIES.to_a.rassoc(@severity)[0] end
Slogger::Base#severity=
# File lib/slogger/common_logger.rb, line 81 def severity=(value) super(BRIDGE_SEVERITIES[value]) end