lib/ougai/logger.rb in ougai-0.7.4 vs lib/ougai/logger.rb in ougai-0.8.0

- old
+ new

@@ -10,28 +10,57 @@ @default_message = 'No message' @exc_key = :err @formatter = create_formatter end - def debug(message, ex = nil, data = nil) - super(to_item(message, ex, data)) + def debug(message = nil, ex = nil, data = nil, &block) + return true if level > DEBUG + if block_given? + args = yield + else + args = [message, ex, data] + end + super(to_item(args), &nil) end - def info(message, ex = nil, data = nil) - super(to_item(message, ex, data)) + def info(message = nil, ex = nil, data = nil) + return true if level > INFO + if block_given? + args = yield + else + args = [message, ex, data] + end + super(to_item(args), &nil) end - def warn(message, ex = nil, data = nil) - super(to_item(message, ex, data)) + def warn(message = nil, ex = nil, data = nil) + return true if level > WARN + if block_given? + args = yield + else + args = [message, ex, data] + end + super(to_item(args), &nil) end - def error(message, ex = nil, data = nil) - super(to_item(message, ex, data)) + def error(message = nil, ex = nil, data = nil) + return true if level > ERROR + if block_given? + args = yield + else + args = [message, ex, data] + end + super(to_item(args), &nil) end - def fatal(message, ex = nil, data = nil) - super(to_item(message, ex, data)) + def fatal(message = nil, ex = nil, data = nil) + if block_given? + args = yield + else + args = [message, ex, data] + end + super(to_item(args), &nil) end def self.broadcast(logger) Module.new do |mdl| ::Logger::Severity.constants.each do |severity| @@ -51,10 +80,12 @@ Formatters::Bunyan.new end private - def to_item(msg, ex, data) + def to_item(args) + msg, ex, data = args + item = {} if ex.nil? # 1 arg if msg.is_a?(Exception) item[:msg] = msg.to_s set_exc(item, msg)