Class: KLog::LogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- KLog::LogFormatter
- Defined in:
- lib/k_log/log_formatter.rb
Overview
Styled Log formatter
Constant Summary collapse
- SEVERITY_TO_COLOR_MAP =
{ 'DEBUG' => '34', 'INFO' => '32', 'WARN' => '33', 'ERROR' => '31', 'FATAL' => '37' }.freeze
Instance Method Summary collapse
Instance Method Details
#call(severity, _timestamp, _prog_name, msg) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/k_log/log_formatter.rb', line 14 def call(severity, , _prog_name, msg) severity = severity.upcase color = SEVERITY_TO_COLOR_MAP[severity] severity_value = format("\033[#{color}m%<severity>-5.5s\033[0m", { severity: severity }) msg = msg.is_a?(String) ? msg : msg.inspect # "%<time>s %<severity>s %<message>s\n", { format( "%<severity>s %<message>s\n", { time: Time.now.strftime('%d|%H:%M:%S'), severity: severity_value, message: msg } ) end |