Sha256: 3626943ee4c34a5f7c9cb21881739a48d85b0aaeba540c89e75cb42eb1ebb919

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

require 'logger'

require 'active_support/logger_silence'
require 'active_support/logger_thread_safe_level'

require 'hickory/formatters/json'
require 'hickory/formatters/simple'

module Hickory
  class Logger < ::Logger
    include ActiveSupport::LoggerThreadSafeLevel
    include ActiveSupport::LoggerSilence

    def initialize(*args)
      super
      self.formatter = Formatters::Simple.new
    end

    SEVERITIY_LABELS = %w(TRACE DEBUG INFO WARN ERROR FATAL UNKNOWN)

    %i[trace debug info warn error fatal unknown].each do |level|

      define_method(level) do |msg = nil, meta={}, &block|
        message = { message: msg }

        message.merge!(meta) if meta.is_a?(Hash) && !meta.empty?

        severity = SEVERITIY_LABELS.index(level.to_s.upcase) - 1

        if block
          send(level, block.call)
        else
          log(severity, message)
        end
      end
    end
  end
end

require 'hickory/railtie' if defined?(Rails)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hickory-0.1.1 lib/hickory/logger.rb