Class: AllStak::Integrations::Logger::BroadcastLogger
- Inherits:
-
Object
- Object
- AllStak::Integrations::Logger::BroadcastLogger
- Defined in:
- lib/allstak/integrations/logger.rb
Overview
Minimal broadcast shim for runtimes without ActiveSupport::BroadcastLogger (plain Ruby, older Rails). Fans every public Logger call out to each delegate; reads (e.g. #level) come from the first. Fail-open per call.
Instance Method Summary collapse
-
#initialize(loggers) ⇒ BroadcastLogger
constructor
A new instance of BroadcastLogger.
-
#level ⇒ Object
Read-ish delegations resolve against the first logger.
- #level=(value) ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(loggers) ⇒ BroadcastLogger
Returns a new instance of BroadcastLogger.
163 164 165 |
# File 'lib/allstak/integrations/logger.rb', line 163 def initialize(loggers) @loggers = Array(loggers) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
193 194 195 196 197 |
# File 'lib/allstak/integrations/logger.rb', line 193 def method_missing(name, *args, &block) target = @loggers.find { |l| l.respond_to?(name) } return super unless target target.public_send(name, *args, &block) end |
Instance Method Details
#level ⇒ Object
Read-ish delegations resolve against the first logger.
181 182 183 |
# File 'lib/allstak/integrations/logger.rb', line 181 def level @loggers.first&.level end |
#level=(value) ⇒ Object
185 186 187 |
# File 'lib/allstak/integrations/logger.rb', line 185 def level=(value) @loggers.each { |l| l.level = value if l.respond_to?(:level=) } end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
189 190 191 |
# File 'lib/allstak/integrations/logger.rb', line 189 def respond_to_missing?(name, include_private = false) @loggers.any? { |l| l.respond_to?(name, include_private) } || super end |