Class: Klogger::Formatters::Go

Inherits:
Abstract
  • Object
show all
Defined in:
lib/klogger/formatters/go.rb

Constant Summary collapse

EXCLUDE_FROM_TAGS =
[:time, :severity, :message].freeze

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Klogger::Abstract

Instance Method Details

#call(_severity, time, _progname, payload) ⇒ Object

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/klogger/formatters/go.rb', line 14

def call(_severity, time, _progname, payload)
  string = String.new
  string << time.strftime('%Y-%m-%d %H:%M:%S %z')
  string << ' '
  string << colorize(payload[:severity].ljust(7, ' ').upcase, payload[:severity].to_sym)
  if payload[:message]
    string << colorize(payload[:message], :white)
    string << ' '
  end
  payload.each do |key, value|
    next if EXCLUDE_FROM_TAGS.include?(key)

    string << colorize("#{key}=", :gray)
    string << colorize(sanitize_value(value), :white)
    string << ' '
  end
  string.strip + "\n"
end