lib/ougai/logger.rb in ougai-1.4.3 vs lib/ougai/logger.rb in ougai-1.4.4

- old
+ new

@@ -1,6 +1,11 @@ module Ougai + # Main Logger + # @attr [String] default_message Use this if log message is not specified (by default this is 'No message'). + # @attr [String] exc_key The field name of Exception (by default this is :err). + # @attr [Hash] with_fields The fields appending to all logs. + # @attr [Proc] before_log Hook before logging. class Logger < ::Logger include Logging attr_accessor :default_message, :exc_key @@ -10,10 +15,12 @@ @exc_key = :err @with_fields = {} @formatter = create_formatter end + # Broadcasts the same logs to the another logger + # @param logger [Logger] The logger receiving broadcast logs. def self.broadcast(logger) Module.new do |mdl| ::Logger::Severity.constants.each do |severity| method_name = severity.downcase.to_sym @@ -33,26 +40,30 @@ super() end end end + # @private def chain(severity, args, fields, hooks) hooks.push(@before_log) if @before_log write(severity, args, merge_fields(@with_fields, fields), hooks) end protected + # @private def append(severity, args) hooks = @before_log ? [@before_log] : [] write(severity, args, @with_fields, hooks) end def create_formatter Formatters::Bunyan.new end + private + def write(severity, args, fields, hooks) data = merge_fields(fields, to_item(args)) hooks.each do |hook| return false if hook.call(data) == false end @@ -70,11 +81,9 @@ create_item_with_3args(msg, ex, data) else # No args { msg: @default_message } end end - - private def create_item_with_1arg(msg) item = {} if msg.is_a?(Exception) item[:msg] = msg.to_s