Class: Spree::EventLogSubscriber

Inherits:
Object
  • Object
show all
Defined in:
app/subscribers/spree/event_log_subscriber.rb

Overview

Logs all Spree events to Rails logger.

Enabled by default. To disable, set Spree::Config.events_log_enabled = false

Events are logged at info level. Sensitive parameters are filtered using Rails.application.config.filter_parameters.

Examples:

Output

[Spree Event] order.complete | payload: {"id"=>1} | 0.5ms

Constant Summary collapse

NAMESPACE =
'spree'

Class Method Summary collapse

Class Method Details

.attach_to_notificationsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/subscribers/spree/event_log_subscriber.rb', line 18

def attach_to_notifications
  # Always detach first to ensure clean state after code reload.
  # The subscription reference is stored on Spree::Events (in lib/, not
  # reloaded by Zeitwerk) so repeated reloads in development do not leak
  # stale AS::N subscriptions when this class is reloaded.
  detach_from_notifications

  Spree::Events.log_subscription = ActiveSupport::Notifications.subscribe(/\.#{NAMESPACE}$/) do |name, start, finish, _id, payload|
    log_event(name, start, finish, payload)
  end

  Rails.logger.info "[Spree Events] Event logging enabled"
end

.attached?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/subscribers/spree/event_log_subscriber.rb', line 38

def attached?
  !Spree::Events.log_subscription.nil?
end

.detach_from_notificationsObject



32
33
34
35
36
# File 'app/subscribers/spree/event_log_subscriber.rb', line 32

def detach_from_notifications
  subscription = Spree::Events.log_subscription
  ActiveSupport::Notifications.unsubscribe(subscription) if subscription
  Spree::Events.log_subscription = nil
end