lib/slogger/common_logger.rb in slogger-0.0.7 vs lib/slogger/common_logger.rb in slogger-0.0.8
- old
+ new
@@ -1,5 +1,7 @@
+require 'logger'
+
module Slogger
#
# 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.
#
@@ -10,11 +12,11 @@
# config.logger = Slogger::CommonLogger.new "rappils", config.log_level, :local0
#
# That's all. The Rails application will log everything to the standard syslog.
#
class CommonLogger < Base
-
+
SEVERITIES = {
:emerg => Syslog::LOG_EMERG,
:alert => Syslog::LOG_ALERT,
:err => Syslog::LOG_ERR,
:info => Syslog::LOG_INFO,
@@ -53,22 +55,28 @@
# Raises an ArgumentError if app_name, severity, or facility is nil.
#
def initialize(app_name, severity, facility)
super app_name, severity, facility, SEVERITIES
end
-
+
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
-
- def add(severity, message = nil, &block)
- log(BRIDGE_SEVERITIES[severity], message, &block)
+
+ 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
-
+
BRIDGE_SEVERITIES.each_key do |severity|
define_method severity do |message = nil, &block|
log BRIDGE_SEVERITIES[severity], message, &block
end