|
|
@ -2,19 +2,22 @@ require 'rainbow' |
|
|
|
|
|
|
|
# ColoredFormatter outputs colored message according to severity |
|
|
|
class ColoredFormatter < Logger::Formatter |
|
|
|
def call(severity, _time, _program_name, message) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength |
|
|
|
full_message = message.is_a?(String) ? message : message.inspect |
|
|
|
case severity |
|
|
|
when 'DEBUG' |
|
|
|
"#{Rainbow(severity).gray.bright.underline.bg(:yellow)} - #{Rainbow(full_message).gray}\n" |
|
|
|
when 'INFO' |
|
|
|
"#{Rainbow(severity).green.bright.underline.bg(:yellow)} - #{Rainbow(full_message).green}\n" |
|
|
|
when 'WARN' |
|
|
|
"#{Rainbow(severity).orange.bright.underline} - #{Rainbow(full_message).orange}\n" |
|
|
|
when 'ERROR' |
|
|
|
"#{Rainbow(severity).red.bright.underline} - #{Rainbow(full_message).red}\n" |
|
|
|
else |
|
|
|
"unknown severity #{severity}\n" |
|
|
|
end |
|
|
|
def call(severity, _time, _program_name, message) # rubocop:disable Metrics/MethodLength |
|
|
|
tint = case severity |
|
|
|
when 'DEBUG' |
|
|
|
:darkgray |
|
|
|
when 'INFO' |
|
|
|
:white |
|
|
|
when 'WARN' |
|
|
|
# :orange |
|
|
|
'#FFC482' |
|
|
|
when 'ERROR' |
|
|
|
:red |
|
|
|
when 'FATAL' |
|
|
|
:magenta |
|
|
|
else |
|
|
|
raise "unknown severity #{severity}" |
|
|
|
end |
|
|
|
"#{Rainbow('╞' + severity.ljust(5) + '╡').bg(:cyan).color(:darkgray)}╠ #{Rainbow(message).color(tint)}\n" |
|
|
|
end |
|
|
|
end |