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
# File 'app/subscribers/spree/event_log_subscriber.rb', line 18

def attach_to_notifications
  # Always detach first to ensure clean state after code reload
  detach_from_notifications

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

  @attached = true
  Rails.logger.info "[Spree Events] Event logging enabled"
end

.attached?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/subscribers/spree/event_log_subscriber.rb', line 36

def attached?
  @attached || false
end

.detach_from_notificationsObject



30
31
32
33
34
# File 'app/subscribers/spree/event_log_subscriber.rb', line 30

def detach_from_notifications
  ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription
  @subscription = nil
  @attached = false
end