Class: Spacebunny::Logger
- Inherits:
-
Object
- Object
- Spacebunny::Logger
- Defined in:
- lib/spacebunny/logger.rb
Overview
Log on multiple outputs at the same time
Usage example:
log_file = File.open(“log/debug.log”, “a”) Logger.new Spacebunny::Logger.new(STDOUT, log_file)
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(*args) ⇒ Logger
constructor
A new instance of Logger.
- #write(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spacebunny/logger.rb', line 10 def initialize(*args) @streams = [] args.each do |a| case a when String # This is a file path @streams << File.open(a, 'a+') else @streams << a end end end |
Instance Method Details
#close ⇒ Object
30 31 32 |
# File 'lib/spacebunny/logger.rb', line 30 def close @streams.each(&:close) end |
#write(*args) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/spacebunny/logger.rb', line 23 def write(*args) @streams.each do |lo| lo.write(*args) lo.flush end end |