Sha256: 888a90cbe315c0220726a0fcefb296a20e125ee2c4592a4ca7e26226aa4699cc

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Timber
  module Overrides
    module LoggerAdd
      def self.included(klass)
        klass.class_eval do
          alias_method :_timber_original_add, :add

          def add(severity, message = nil, progname = nil)
            # Extract the message: https://github.com/ruby/ruby/blob/f6e77b9d3555c1fbaa8aab1cdc0bd6bde95f62c6/lib/logger.rb#L461-L468
            progname ||= @progname
            if message.nil?
              if block_given?
                message = yield
              else
                message = progname
                progname = @progname
              end
            end

            if message.is_a?(::Timber::Event)
              if self.is_a?(::Timber::Logger)
                _timber_original_add(severity, message, progname)
              else
                if message.message.nil?
                  STDOUT.write message.inspect
                end
                _timber_original_add(severity, message.message, progname)
              end
            else
              _timber_original_add(severity, message, progname)
            end
          end
        end
      end
    end
  end
end

require "logger"

::Logger.send(:include, Timber::Overrides::LoggerAdd)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-1.1.13 lib/timber/overrides/logger_add.rb
timber-1.1.12 lib/timber/overrides/logger_add.rb