class Leveret::LogFormatter
Prettier logging than the default
Constants
- SEVERITY_TO_COLOR_MAP
ANSI colour codes for different message types
Public Instance Methods
call(severity, datetime, _progname, msg)
click to toggle source
Build a pretty formatted log line
@param [String] severity Log level, one of debug, info, warn, error, fatal or unknown @param [Time] datetime Timestamp of log event @param [String] _progname (Unused) the name of the progname set in the logger @param [String] msg Body of the log message
@return [String] Formatted and coloured log message in the format:
"YYYY-MM-DD HH:MM:SS:USEC [SEVERITY] MESSAGE (pid:Process ID)"
# 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