lib/ougai/logging.rb in ougai-1.3.0 vs lib/ougai/logging.rb in ougai-1.4.0

- old
+ new

@@ -2,37 +2,27 @@ module Logging attr_accessor :with_fields attr_writer :before_log def debug(message = nil, ex = nil, data = nil, &block) - return true if level > Logger::DEBUG - args = block ? yield : [message, ex, data] - append(Logger::DEBUG, args) + log(Logger::DEBUG, message, ex, data, block) end def info(message = nil, ex = nil, data = nil, &block) - return true if level > Logger::INFO - args = block ? yield : [message, ex, data] - append(Logger::INFO, args) + log(Logger::INFO, message, ex, data, block) end def warn(message = nil, ex = nil, data = nil, &block) - return true if level > Logger::WARN - args = block ? yield : [message, ex, data] - append(Logger::WARN, args) + log(Logger::WARN, message, ex, data, block) end def error(message = nil, ex = nil, data = nil, &block) - return true if level > Logger::ERROR - args = block ? yield : [message, ex, data] - append(Logger::ERROR, args) + log(Logger::ERROR, message, ex, data, block) end def fatal(message = nil, ex = nil, data = nil, &block) - return true if level > Logger::FATAL - args = block ? yield : [message, ex, data] - append(Logger::FATAL, args) + log(Logger::FATAL, message, ex, data, block) end def unknown(message = nil, ex = nil, data = nil, &block) args = block ? yield : [message, ex, data] append(Logger::UNKNOWN, args) @@ -58,8 +48,16 @@ (base_val + new_val).uniq else new_val end end + end + + private + + def log(severity, message, ex, data, block) + return true if level > severity + args = block ? block.call : [message, ex, data] + append(severity, args) end end end