Loggability::Formatter::

Color class

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( * )

Create a new formatter.

# File lib/loggability/formatter/color.rb, line 30
def initialize( * )
        super
        @color_enabled = COLOR_TERMINAL_NAMES.match( ENV['TERM'] ) ? true : false
end

Public Instance Methods

msg2str( msg, severity )

Format the specified msg for output to the log.

# File lib/loggability/formatter/color.rb, line 41
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