Class: StandardCircuit::Notifiers::Logger
- Inherits:
-
Object
- Object
- StandardCircuit::Notifiers::Logger
- Defined in:
- lib/standard_circuit/notifiers/logger.rb
Overview
Subscribes to standard_circuit.circuit.* events and writes a human-readable log line for each transition. Always-on by default; pass a custom logger via ‘StandardCircuit.config.logger=`.
Constant Summary collapse
- TRANSITION_EVENTS =
%w[ standard_circuit.circuit.opened standard_circuit.circuit.closed standard_circuit.circuit.degraded ].freeze
Instance Method Summary collapse
- #call(event_name, payload) ⇒ Object
-
#initialize(logger = nil) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(logger = nil) ⇒ Logger
Returns a new instance of Logger.
15 16 17 |
# File 'lib/standard_circuit/notifiers/logger.rb', line 15 def initialize(logger = nil) @logger = logger || ::Logger.new($stdout) end |
Instance Method Details
#call(event_name, payload) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/standard_circuit/notifiers/logger.rb', line 19 def call(event_name, payload) return unless TRANSITION_EVENTS.include?(event_name) = (event_name, payload) level = event_name == "standard_circuit.circuit.opened" ? :warn : :info @logger.public_send(level, ) end |