Class: Yescode::LogfmtFormatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/yescode/logfmt_formatter.rb

Instance Method Summary collapse

Instance Method Details

#call(severity, datetime, progname, msg) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/yescode/logfmt_formatter.rb', line 5

def call(severity, datetime, progname, msg)
  timestamp = datetime.strftime('%Y-%m-%d %H:%M:%S.%L')

  parts = {
    level: severity.downcase,
    in: progname
  }

  parts.merge!(msg)

  output = "[#{timestamp}] #{parts.reject { |_, v| v.nil? }.map { |k, v| "#{k}=#{v}" }.join(' ')}\n"

  if severity.downcase == "debug"
    blue(output)
  else
    output
  end
end