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