Class: TinyCI::MultiLogger
- Inherits:
-
Object
- Object
- TinyCI::MultiLogger
- Defined in:
- lib/tinyci/multi_logger.rb
Overview
This class allows logging to both STDOUT and to a file with a single call.
Constant Summary collapse
- FORMAT =
Proc.new do |severity, datetime, progname, msg| "[#{datetime.strftime "%T"}] #{msg}\n" end
Instance Attribute Summary collapse
-
#quiet ⇒ Boolean
Disables logging to STDOUT.
Instance Method Summary collapse
-
#initialize(quiet: false, path: nil) ⇒ MultiLogger
constructor
Constructor.
- #output_path=(path) ⇒ Object
- #targets ⇒ Object
Constructor Details
#initialize(quiet: false, path: nil) ⇒ MultiLogger
Constructor
17 18 19 20 21 22 23 24 25 |
# File 'lib/tinyci/multi_logger.rb', line 17 def initialize(quiet: false, path: nil) @file_logger = nil self.output_path = path @quiet = quiet @stdout_logger = Logger.new($stdout) @stdout_logger.formatter = FORMAT @stdout_logger.level = Logger::INFO end |
Instance Attribute Details
#quiet ⇒ Boolean
Disables logging to STDOUT
6 7 8 |
# File 'lib/tinyci/multi_logger.rb', line 6 def quiet @quiet end |
Instance Method Details
#output_path=(path) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/tinyci/multi_logger.rb', line 35 def output_path=(path) if path @file_logger = Logger.new(path) @file_logger.formatter = FORMAT @file_logger.level = Logger::INFO end end |
#targets ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/tinyci/multi_logger.rb', line 27 def targets logs = [] logs << @file_logger if @file_logger logs << @stdout_logger unless @quiet logs end |