ANSI color log formatter. Outputs log messages color-coded by their severity if the current terminal appears to support it.
Pattern for matching color terminals
ANSI color escapes keyed by severity
ANSI reset
Create a new formatter.
# File lib/loggability/formatter/color.rb, line 31
def initialize( * )
super
@color_enabled = COLOR_TERMINAL_NAMES.match( ENV['TERM'] ) ? true : false
end
Format the specified msg for output to the log.
# File lib/loggability/formatter/color.rb, line 42
def msg2str( msg, severity )
msg = super
if @color_enabled
color = severity.downcase.to_sym
msg = [ LEVEL_CODES[color], msg, RESET ].join( '' )
end
return msg
end