Class: DRbService::ColorLogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- DRbService::ColorLogFormatter
- Extended by:
- ANSIColorUtilities
- Defined in:
- lib/drbservice/utils.rb
Overview
A ANSI-colorized formatter for Logger instances.
Usage
require 'drbservice/utils'
DRbService.logger.formatter = DRbService::ColorLogFormatter.new( DRbService.logger )
Version
$Id: utils.rb,v 87bc5aa9e2be 2011/08/29 21:05:42 ged $
Authors
-
Michael Granger <[email protected]>
:include: LICENSE
–
Please see the file LICENSE in the ‘docs’ directory for licensing details.
Constant Summary collapse
- LEVEL_FORMATS =
Color settings
{ :debug => colorize( :bold, :black ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"}, :info => colorize( :normal ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"}, :warn => colorize( :bold, :yellow ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"}, :error => colorize( :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"}, :fatal => colorize( :bold, :red, :on_white ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"}, }
Constants included from ANSIColorUtilities
ANSIColorUtilities::ANSI_ATTRIBUTES
Instance Attribute Summary collapse
-
#logger ⇒ Object
The Logger object associated with the formatter.
-
#settings ⇒ Object
The formats, by level.
Instance Method Summary collapse
-
#call(severity, time, progname, msg) ⇒ Object
Log using the format associated with the severity.
-
#initialize(logger, settings = {}) ⇒ ColorLogFormatter
constructor
Initialize the formatter with a reference to the logger so it can check for log level.
Methods included from ANSIColorUtilities
Constructor Details
#initialize(logger, settings = {}) ⇒ ColorLogFormatter
Initialize the formatter with a reference to the logger so it can check for log level.
190 191 192 193 194 195 196 197 |
# File 'lib/drbservice/utils.rb', line 190 def initialize( logger, settings={} ) # :notnew: settings = LEVEL_FORMATS.merge( settings ) @logger = logger @settings = settings super() end |
Instance Attribute Details
#logger ⇒ Object
The Logger object associated with the formatter
204 205 206 |
# File 'lib/drbservice/utils.rb', line 204 def logger @logger end |
#settings ⇒ Object
The formats, by level
207 208 209 |
# File 'lib/drbservice/utils.rb', line 207 def settings @settings end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
Log using the format associated with the severity
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/drbservice/utils.rb', line 211 def call( severity, time, progname, msg ) args = [ time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s time.usec, # %2$d Process.pid, # %3$d Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s severity, # %5$s progname, # %6$s msg # %7$s ] return self.settings[ severity.downcase.to_sym ] % args end |