Class: Leveret::LogFormatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/leveret/log_formatter.rb

Overview

Prettier logging than the default

Constant Summary collapse

SEVERITY_TO_COLOR_MAP =

ANSI colour codes for different message types

{ 'DEBUG' => '0;37', 'INFO' => '32', 'WARN' => '33', 'ERROR' => '31', 'FATAL' => '31',
'UNKNOWN' => '37' }.freeze

Instance Method Summary collapse

Instance Method Details

#call(severity, datetime, _progname, msg) ⇒ String

Build a pretty formatted log line



17
18
19
20
21
22
# File 'lib/leveret/log_formatter.rb', line 17

def call(severity, datetime, _progname, msg)
  formatted_time = datetime.strftime("%Y-%m-%d %H:%M:%S") << datetime.usec.to_s[0..2].rjust(3)
  color = SEVERITY_TO_COLOR_MAP[severity]

  "\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{severity}\033[0m] #{msg2str(msg)} (pid:#{Process.pid})\n"
end