Sha256: 336080604c5b211424b098ee3e47525f97cc1acd6259933d569312c377df927f

Contents?: true

Size: 977 Bytes

Versions: 3

Compression:

Stored size: 977 Bytes

Contents

module Loga
  module Formatters
    class SimpleFormatter < Logger::Formatter
      include TaggedLogging::Formatter

      FORMAT = "%s, [%s #%d]%s %s\n".freeze

      def call(severity, time, _progname, object)
        FORMAT % [
          severity[0..0],
          time.iso8601(6),
          Process.pid,
          tags,
          compute_message(object),
        ]
      end

      private

      def compute_message(object)
        case object
        when Loga::Event
          compute_event_message(object)
        else
          msg2str(object)
        end
      end

      def compute_event_message(event)
        components = [event.message]

        %i(type data exception).each do |attr|
          if event.public_send(attr)
            components.push "#{attr}=#{event.public_send(attr)}"
          end
        end

        components.join(' ')
      end

      def tags
        current_tags.empty? ? '' : "[#{current_tags.join(' ')}]"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loga-2.1.2 lib/loga/formatters/simple_formatter.rb
loga-2.1.1 lib/loga/formatters/simple_formatter.rb
loga-2.1.0 lib/loga/formatters/simple_formatter.rb