Class: Lcoveralls::ColorFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Lcoveralls::ColorFormatter
- Defined in:
- lib/lcoveralls/color_formatter.rb
Constant Summary collapse
- COLOR_CODES =
{ 'Warning' => '35', 'Error' => '31', 'Fatal' => '31;1', 'Unknown' => '31;1' }
Instance Method Summary collapse
- #call(severity, datetime, progname, msg) ⇒ Object
-
#initialize(color) ⇒ ColorFormatter
constructor
A new instance of ColorFormatter.
Constructor Details
#initialize(color) ⇒ ColorFormatter
30 31 32 |
# File 'lib/lcoveralls/color_formatter.rb', line 30 def initialize(color) @color = color end |
Instance Method Details
#call(severity, datetime, progname, msg) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lcoveralls/color_formatter.rb', line 34 def call(severity, datetime, progname, msg) severity.capitalize! if severity == 'Warn' then severity = 'Warning' end if %w[Warning Error Fatal Unknown].include?(severity) then msg = "#{severity}: #{msg}" end color_code = COLOR_CODES[severity] if @color if color_code then "\x1b[#{color_code}m#{msg}\x1b[0m\n" else "#{msg}\n" end end |