Class: PaulBunyan::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/paul_bunyan/railtie/log_subscriber.rb

Constant Summary collapse

ACTION_PAYLOAD_KEYS =

Handle the process_action event in the action_controller namespace

We’re using this to capture the vast majority of our info that goes into the log line

[:method, :controller, :action, :format, :path, :status, :view_runtime, :db_runtime]

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.action_controller_eventsObject (readonly)

Returns the value of attribute action_controller_events.



39
40
41
# File 'lib/paul_bunyan/railtie/log_subscriber.rb', line 39

def action_controller_events
  @action_controller_events
end

.action_view_eventsObject (readonly)

Returns the value of attribute action_view_events.



39
40
41
# File 'lib/paul_bunyan/railtie/log_subscriber.rb', line 39

def action_view_events
  @action_view_events
end

Class Method Details

.event_patternsObject

Build an array of event patterns from the action_controller_events set for use in finding subscriptions we should add and ones we should remove from the default subscribers



56
57
58
59
# File 'lib/paul_bunyan/railtie/log_subscriber.rb', line 56

def self.event_patterns
  action_controller_events.map{ |event| "#{event}.action_controller" } +
    action_view_events.map { |event| "#{event}.action_view" }
end

.subscribe_to_events(notifier = ActiveSupport::Notifications) ⇒ Object

Subscribe to the events we’ve registered using action_controller_event



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/paul_bunyan/railtie/log_subscriber.rb', line 62

def self.subscribe_to_events(notifier = ActiveSupport::Notifications)
  subscriber = new
  notifier   = notifier

  subscribers << subscriber

  event_patterns.each do |pattern|
    if Rails::VERSION::MAJOR >= 6
      subscriber.patterns[pattern] = notifier.subscribe(pattern, subscriber)
    else
      subscriber.patterns << pattern
      notifier.subscribe(pattern, subscriber)
    end
  end
end

Instance Method Details

#loggerObject



134
135
136
# File 'lib/paul_bunyan/railtie/log_subscriber.rb', line 134

def logger
  PaulBunyan.logger
end