class Loggability::Formatter::Color
ANSI color log formatter. Outputs log messages color-coded by their severity if the current terminal appears to support it.
Constants
- COLOR_TERMINAL_NAMES
Pattern for matching color terminals
- LEVEL_CODES
ANSI color escapes keyed by severity
- RESET
ANSI reset
Public Class Methods
new( * )
click to toggle source
Create a new formatter.
Calls superclass method
Loggability::Formatter::Default.new
# File lib/loggability/formatter/color.rb, line 31 def initialize( * ) super @color_enabled = COLOR_TERMINAL_NAMES.match( ENV['TERM'] ) ? true : false end
Public Instance Methods
msg2str( msg, severity )
click to toggle source
Format the specified msg
for output to the log.
Calls superclass method
Loggability::Formatter#msg2str
# 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