Class: Bauxite::Loggers::CompositeLogger
- Inherits:
-
Object
- Object
- Bauxite::Loggers::CompositeLogger
- Defined in:
- lib/bauxite/loggers/composite.rb
Overview
Composite logger.
This composite logger forwards logging calls to each of its children.
Composite logger options include:
loggers-
A comma-separated list of logger names.
Instance Method Summary collapse
-
#debug_prompt ⇒ Object
Returns a colorized debug prompt.
-
#finalize(ctx) ⇒ Object
Completes the log execution.
-
#initialize(options, loggers = nil) ⇒ CompositeLogger
constructor
Constructs a new composite logger instance.
-
#log(s, type = :info) ⇒ Object
Prints the specified string.
-
#log_cmd(action, &block) ⇒ Object
Pretty prints action information and status.
-
#progress(value) ⇒ Object
Updates action progress.
Constructor Details
#initialize(options, loggers = nil) ⇒ CompositeLogger
Constructs a new composite logger instance.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bauxite/loggers/composite.rb', line 33 def initialize(, loggers = nil) unless loggers unless [:loggers] raise ArgumentError, "Missing required logger option 'loggers'. "+ "The value of this option is a comma-separated list of valid loggers. "+ "For example loggers=xterm,file." end loggers = [:loggers].split(',') end @loggers = loggers.map do |l| Bauxite::Context::load_logger(l, ) end end |
Instance Method Details
#debug_prompt ⇒ Object
Returns a colorized debug prompt.
This implementation returns the debug_prompt of the first logger.
62 63 64 |
# File 'lib/bauxite/loggers/composite.rb', line 62 def debug_prompt @loggers[0].debug_prompt end |
#finalize(ctx) ⇒ Object
Completes the log execution.
81 82 83 |
# File 'lib/bauxite/loggers/composite.rb', line 81 def finalize(ctx) @loggers.each { |l| l.finalize(ctx) } end |
#log(s, type = :info) ⇒ Object
Prints the specified string.
See Bauxite::Loggers::NullLogger#print
75 76 77 |
# File 'lib/bauxite/loggers/composite.rb', line 75 def log(s, type = :info) @loggers.each { |l| l.log(s, type) } end |
#log_cmd(action, &block) ⇒ Object
Pretty prints action information and status.
This implementation only yileds in the first logger.
Additional loggers are called after the block completed.
54 55 56 |
# File 'lib/bauxite/loggers/composite.rb', line 54 def log_cmd(action, &block) _log_cmd_block(@loggers, action, &block) end |
#progress(value) ⇒ Object
Updates action progress.
67 68 69 |
# File 'lib/bauxite/loggers/composite.rb', line 67 def progress(value) @loggers.each { |l| l.progress(value) } end |