Class: Onlylogs::MultiDevice
- Inherits:
-
Object
- Object
- Onlylogs::MultiDevice
- Defined in:
- lib/onlylogs/multi_device.rb
Overview
A Logger log device that fans each line out to several underlying devices, e.g. the local $stdout fallback plus a remote sink (Onlylogs::SocketDevice / Onlylogs::HttpDevice).
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(*devices) ⇒ MultiDevice
constructor
A new instance of MultiDevice.
- #write(message) ⇒ Object
Constructor Details
#initialize(*devices) ⇒ MultiDevice
Returns a new instance of MultiDevice.
7 8 9 |
# File 'lib/onlylogs/multi_device.rb', line 7 def initialize(*devices) @devices = devices.compact end |
Instance Method Details
#close ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/onlylogs/multi_device.rb', line 17 def close @devices.each do |device| # Never close the process' standard streams — the app owns them, not us. next if device.equal?($stdout) || device.equal?($stderr) device.close if device.respond_to?(:close) end end |
#flush ⇒ Object
26 27 28 |
# File 'lib/onlylogs/multi_device.rb', line 26 def flush @devices.each { |device| device.flush if device.respond_to?(:flush) } end |
#write(message) ⇒ Object
11 12 13 14 15 |
# File 'lib/onlylogs/multi_device.rb', line 11 def write() return if .nil? || .empty? @devices.each { |device| device.write() } end |