Sha256: 2e956aaa24555a36b60888a3eb8b54bd1cd5e22bbdb654686dc18a6d3dd9ba00

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

module Ougai
  module Logging
    attr_accessor :with_fields
    attr_writer :before_log

    def debug(message = nil, ex = nil, data = nil, &block)
      log(Logger::DEBUG, message, ex, data, block)
    end

    def info(message = nil, ex = nil, data = nil, &block)
      log(Logger::INFO, message, ex, data, block)
    end

    def warn(message = nil, ex = nil, data = nil, &block)
      log(Logger::WARN, message, ex, data, block)
    end

    def error(message = nil, ex = nil, data = nil, &block)
      log(Logger::ERROR, message, ex, data, block)
    end

    def fatal(message = nil, ex = nil, data = nil, &block)
      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)
    end

    def child(fields = {})
      ChildLogger.new(self, fields)
    end

    def chain(_severity, _args, _fields, _hooks)
      raise NotImplementedError
    end

    protected

    def append(severity, args)
      raise NotImplementedError
    end

    def merge_fields(base_data, new_data)
      base_data.merge(new_data) do |_, base_val, new_val|
        if base_val.is_a?(Array) and new_val.is_a?(Array)
          (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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ougai-1.4.3 lib/ougai/logging.rb
ougai-1.4.2 lib/ougai/logging.rb
ougai-1.4.1 lib/ougai/logging.rb
ougai-1.4.0 lib/ougai/logging.rb