Class: BetterService::Subscribers::LogSubscriber
- Inherits:
-
Object
- Object
- BetterService::Subscribers::LogSubscriber
- Defined in:
- lib/better_service/subscribers/log_subscriber.rb
Overview
LogSubscriber - Built-in subscriber that logs service events
This subscriber logs all service events to Rails.logger. Enable it in configuration to get automatic logging for all services.
Class Attribute Summary collapse
-
.subscriptions ⇒ Array<ActiveSupport::Notifications::Fanout::Subscriber>
readonly
Storage for ActiveSupport::Notifications subscriptions.
Class Method Summary collapse
-
.attach ⇒ void
Attach the subscriber to ActiveSupport::Notifications.
-
.detach ⇒ void
Detach the subscriber from ActiveSupport::Notifications.
Class Attribute Details
.subscriptions ⇒ Array<ActiveSupport::Notifications::Fanout::Subscriber> (readonly)
Storage for ActiveSupport::Notifications subscriptions
20 21 22 |
# File 'lib/better_service/subscribers/log_subscriber.rb', line 20 def subscriptions @subscriptions end |
Class Method Details
.attach ⇒ void
This method returns an undefined value.
Attach the subscriber to ActiveSupport::Notifications
This method is called automatically when subscriber is enabled. It subscribes to all service.* events.
28 29 30 31 32 |
# File 'lib/better_service/subscribers/log_subscriber.rb', line 28 def attach @subscriptions ||= [] subscribe_to_service_events subscribe_to_cache_events end |
.detach ⇒ void
This method returns an undefined value.
Detach the subscriber from ActiveSupport::Notifications
Removes all subscriptions. Useful for testing.
39 40 41 42 43 44 45 46 |
# File 'lib/better_service/subscribers/log_subscriber.rb', line 39 def detach if @subscriptions @subscriptions.each do |subscription| ActiveSupport::Notifications.unsubscribe(subscription) end end @subscriptions = [] end |