Class: Hoover::ActionControllerLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/hoover/log_subscribers/action_controller_log_subscriber.rb

Constant Summary collapse

INTERNAL_PARAMS =
%w(controller action format _method only_path)

Instance Method Summary collapse

Instance Method Details

#process_action(event) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 18

def process_action(event)
  payload   = event.payload
  additions = ActionController::Base.log_process_action(payload)

  runtimes  = additions.inject({}) do |hash, string|
    name, time = string.split(':')
    hash[name] = time.to_f
    hash
  end

  status = payload[:status]
  if status.nil? && payload[:exception].present?
    status = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[payload[:exception].first]) rescue nil
  end

  Hoover.add(:status => status,
             :duration => event.duration)
  Hoover.add :runtimes => runtimes unless runtimes.blank?
end

#redirect_to(event) ⇒ Object



42
43
44
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 42

def redirect_to(event)
  Hoover.add(:redirected_to => event.payload[:location])
end

#send_data(event) ⇒ Object



46
47
48
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 46

def send_data(event)
  Hoover.add(:sent_data => { :filename => event.payload[:filename], :runtime => event.duration })
end

#send_file(event) ⇒ Object



38
39
40
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 38

def send_file(event)
  Hoover.add(:sent_file => { :path => event.payload[:path], :runtime => event.duration })
end

#start_processing(event) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 8

def start_processing(event)
  payload = event.payload
  params  = payload[:params].except(*INTERNAL_PARAMS)

  Hoover.add(:controller => payload[:controller],
             :action => payload[:action],
             :params => params,
             :format => payload[:formats].first.to_s.upcase)
end