Class: NextStation::Logging::Formatter::Console

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/next_station/logging/formatters/console.rb

Constant Summary collapse

SEVERITY_COLORS =

ANSI color codes

{
  "DEBUG" => "\e[36m", # cyan
  "INFO"  => "\e[32m", # green
  "WARN"  => "\e[33m", # yellow
  "ERROR" => "\e[31m", # red
  "FATAL" => "\e[35m"  # magenta
}.freeze
OPERATION_COLOR =

blue

"\e[34m"
STEP_COLOR =

gray

"\e[90m"
RESET_COLOR =
"\e[0m"

Instance Method Summary collapse

Instance Method Details

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



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/next_station/logging/formatters/console.rb', line 22

def call(severity, datetime, _progname, msg)
  msg = msg.is_a?(Hash) ? msg : { message: msg.to_s }

  operation = msg[:operation]
  step_name = msg[:step_name] ? "/#{msg[:step_name]}" : ""
  payload   = msg[:payload] unless msg[:payload].to_h.empty?

  sev  = "#{SEVERITY_COLORS[severity]}#{severity[0]}#{RESET_COLOR}"
  op   = "#{OPERATION_COLOR}#{operation}#{RESET_COLOR}"
  step = step_name.empty? ? "" : "#{STEP_COLOR}#{step_name}#{RESET_COLOR}"

  "[#{sev}][#{datetime.strftime('%Y-%m-%d %H:%M:%S')}][#{op}#{step}] -- #{msg[:message]} #{payload}\n"
end