Class: Lumberjack::Device::Multi
- Inherits:
-
Lumberjack::Device
- Object
- Lumberjack::Device
- Lumberjack::Device::Multi
- Defined in:
- lib/lumberjack/device/multi.rb
Overview
A multiplexing logging device that broadcasts log entries to multiple target devices simultaneously. This device enables sophisticated logging architectures where a single log entry needs to be processed by multiple output destinations, each potentially with different formatting, filtering, or storage mechanisms.
The Multi device acts as a fan-out mechanism, ensuring that all configured devices receive every log entry while maintaining independent processing pipelines. This is particularly useful for creating redundant logging systems, separating log streams by concern, or implementing complex routing logic.
All device lifecycle methods (flush, close, reopen) are propagated to all child devices, ensuring consistent state management across the entire logging topology.
Instance Attribute Summary collapse
-
#devices ⇒ Object
readonly
Returns the value of attribute devices.
Instance Method Summary collapse
-
#close ⇒ void
Close all configured devices and release their resources.
-
#datetime_format ⇒ String?
Get the datetime format from the first device that has one configured.
-
#datetime_format=(format) ⇒ void
Set the datetime format on all configured devices that support it.
-
#flush ⇒ void
Flush all configured devices to ensure buffered data is written to their respective destinations.
-
#initialize(*devices) ⇒ Multi
constructor
Initialize a new Multi device with the specified target devices.
-
#reopen(logdev = nil) ⇒ void
Reopen all configured devices, optionally with a new log destination.
-
#write(entry) ⇒ void
Broadcast a log entry to all configured devices.
Methods inherited from Lumberjack::Device
Constructor Details
#initialize(*devices) ⇒ Multi
Initialize a new Multi device with the specified target devices. The device accepts multiple devices either as individual arguments or as arrays, automatically flattening nested arrays for convenient configuration.
35 36 37 |
# File 'lib/lumberjack/device/multi.rb', line 35 def initialize(*devices) @devices = devices.flatten end |
Instance Attribute Details
#devices ⇒ Object (readonly)
Returns the value of attribute devices.
23 24 25 |
# File 'lib/lumberjack/device/multi.rb', line 23 def devices @devices end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Close all configured devices and release their resources. This method calls close on each device in sequence, ensuring proper cleanup of file handles, network connections, and other resources across all output destinations.
68 69 70 71 72 |
# File 'lib/lumberjack/device/multi.rb', line 68 def close devices.each do |device| device.close end end |
#datetime_format ⇒ String?
Get the datetime format from the first device that has one configured. This method searches through the configured devices and returns the datetime format from the first device that provides one.
93 94 95 |
# File 'lib/lumberjack/device/multi.rb', line 93 def datetime_format devices.detect(&:datetime_format).datetime_format end |
#datetime_format=(format) ⇒ void
This method returns an undefined value.
Set the datetime format on all configured devices that support it. This method propagates the format setting to each device, allowing coordinated timestamp formatting across all output destinations.
103 104 105 106 107 |
# File 'lib/lumberjack/device/multi.rb', line 103 def datetime_format=(format) devices.each do |device| device.datetime_format = format end end |
#flush ⇒ void
This method returns an undefined value.
Flush all configured devices to ensure buffered data is written to their respective destinations. This method calls flush on each device in sequence, ensuring consistent state across all output destinations.
57 58 59 60 61 |
# File 'lib/lumberjack/device/multi.rb', line 57 def flush devices.each do |device| device.flush end end |
#reopen(logdev = nil) ⇒ void
This method returns an undefined value.
Reopen all configured devices, optionally with a new log destination. This method calls reopen on each device in sequence, which is typically used for log rotation scenarios or when changing output destinations.
81 82 83 84 85 |
# File 'lib/lumberjack/device/multi.rb', line 81 def reopen(logdev = nil) devices.each do |device| device.reopen(logdev = nil) end end |
#write(entry) ⇒ void
This method returns an undefined value.
Broadcast a log entry to all configured devices. Each device receives the same LogEntry object and processes it according to its own configuration, formatting, and output logic. Devices are processed sequentially in the order they were configured.
46 47 48 49 50 |
# File 'lib/lumberjack/device/multi.rb', line 46 def write(entry) devices.each do |device| device.write(entry) end end |