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



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 15

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

  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} #{Rack::Utils::HTTP_STATUS_CODES[status]}",
             :duration => "%.0f" % event.duration)
  Hoover.add :additions => additions.join(" | ") unless additions.blank?
end

#redirect_to(event) ⇒ Object



33
34
35
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 33

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

#send_data(event) ⇒ Object



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

def send_data(event)
  Hoover.add(:sent_data, "%s (%.1fms)" % [event.payload[:filename], event.duration])
end

#send_file(event) ⇒ Object



29
30
31
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 29

def send_file(event)
  Hoover.add(:sent_file, "%s (%.1fms)" % [event.payload[:path], event.duration])
end

#start_processing(event) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/hoover/log_subscribers/action_controller_log_subscriber.rb', line 5

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