Class: Arrow::Logger::ColorOutputter
- Inherits:
-
FileOutputter
- Object
- Outputter
- FileOutputter
- Arrow::Logger::ColorOutputter
- Defined in:
- lib/arrow/logger/coloroutputter.rb
Overview
A derivative of Arrow::Logger::FileOutputter that outputs logging messages in ANSI colors according to their level.
Authors
-
Michael Granger <[email protected]>
Please see the file LICENSE in the top-level directory for licensing details.
Constant Summary collapse
- AnsiAttributes =
Set some ANSI escape code constants (Shamelessly stolen from Perl’s Term::ANSIColor by Russ Allbery <[email protected]> and Zenin <[email protected]>
{ 'clear' => 0, 'reset' => 0, 'bold' => 1, 'dark' => 2, 'underline' => 4, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'concealed' => 8, 'black' => 30, 'on_black' => 40, 'red' => 31, 'on_red' => 41, 'green' => 32, 'on_green' => 42, 'yellow' => 33, 'on_yellow' => 43, 'blue' => 34, 'on_blue' => 44, 'magenta' => 35, 'on_magenta' => 45, 'cyan' => 36, 'on_cyan' => 46, 'white' => 37, 'on_white' => 47 }
- DEFAULT_COLOR_SCHEME =
Default color map: :level => %wscheme
{ :debug => %w{dark white}, :info => %w{cyan}, :notice => %w{bold cyan}, :warning => %w{bold yellow}, :error => %w{bold red}, :crit => %w{bold white on_red}, :alert => %w{bold blink white on_red}, :emerg => %w{bold blink yellow on_red}, }
- DEFAULT_DESCRIPTION =
Default decription used when creating instances
"Logging Outputter"
- DEFAULT_FORMAT =
The default logging output format
%q{#{time.strftime('%Y/%m/%d %H:%M:%S')} [#{level}]: #{name} } + %q{#{frame ? '('+frame+')' : ''}: #{msg}}
Instance Attribute Summary collapse
-
#color_scheme ⇒ Object
readonly
The color scheme hash for this logger.
Attributes inherited from FileOutputter
Attributes inherited from Outputter
Instance Method Summary collapse
-
#initialize(uri, description = DEFAULT_DESCRIPTION, format = DEFAULT_FORMAT) ⇒ ColorOutputter
constructor
Override the default to add color scheme instance variable.
-
#write(time, level, name, frame, msg) ⇒ Object
Write the given
level
,name
,frame
, andmsg
to the logfile.
Methods inherited from Outputter
create, derivativeDirs, #inspect, parse_uri
Constructor Details
#initialize(uri, description = DEFAULT_DESCRIPTION, format = DEFAULT_FORMAT) ⇒ ColorOutputter
Override the default to add color scheme instance variable
63 64 65 66 |
# File 'lib/arrow/logger/coloroutputter.rb', line 63 def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT ) # :notnew: super @color_scheme = DEFAULT_COLOR_SCHEME.dup end |
Instance Attribute Details
#color_scheme ⇒ Object (readonly)
The color scheme hash for this logger
74 75 76 |
# File 'lib/arrow/logger/coloroutputter.rb', line 74 def color_scheme @color_scheme end |
Instance Method Details
#write(time, level, name, frame, msg) ⇒ Object
Write the given level
, name
, frame
, and msg
to the logfile.
78 79 80 81 82 83 84 |
# File 'lib/arrow/logger/coloroutputter.rb', line 78 def write( time, level, name, frame, msg ) colors = @color_scheme[level] super do |msg| color_msg = colorize( msg, colors ) @io.puts( color_msg ) end end |