Class: LogSanity::LogSubscriber::ActionController

Inherits:
Base
  • Object
show all
Defined in:
lib/log_sanity/log_subscribers/action_controller.rb

Constant Summary collapse

INTERNAL_PARAMS =
%w(controller action format _method only_path)

Instance Method Summary collapse

Instance Method Details

#halted_callback(event) ⇒ Object



48
49
50
# File 'lib/log_sanity/log_subscribers/action_controller.rb', line 48

def halted_callback(event)
  log 'filter_chain_halt', event.payload[:filter].inspect
end

#process_action(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/log_sanity/log_subscribers/action_controller.rb', line 6

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

  # log 'method', payload[:method]
  # log 'path', payload[:path]
  # log 'controller', payload[:controller]
  # log 'action', payload[:action]
  log 'route', "#{payload[:controller]}##{payload[:action]}"
  log 'format', format
  log 'params', params if params.present?

  status = payload[:status]
  if status.nil? && payload[:exception].present?
    exception_class_name = payload[:exception].first
    status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
  end

  durations = {'total' => event.duration.round}
  queries   = {}
  additions = ::ActionController::Base.log_process_action(payload)
  additions.each do |add|
    if add =~ /^([^:]+):?\s*([0-9.]+)(ms)?/
      ms = $2.to_f.round
      name = $1.downcase
      durations[name] = ms if ms > 0
    end
    if name and add =~ /[^0-9]([0-9]+) quer/
      q_real = $1.to_i
      if q_real > 0 and add =~ /[^0-9]([0-9]+) cached/
        q_real -= $1.to_i # exclude cached queries
      end
      queries[name] = q_real if q_real > 0
    end
  end

  log 'queries', queries if queries.any?
  log 'duration', durations
  log 'status', status
end

#redirect_to(event) ⇒ Object



56
57
58
# File 'lib/log_sanity/log_subscribers/action_controller.rb', line 56

def redirect_to(event)
  log 'redirect', event.payload[:location]
end

#send_data(event) ⇒ Object



60
61
62
# File 'lib/log_sanity/log_subscribers/action_controller.rb', line 60

def send_data(event)
  log 'send_data', event.payload[:filename] || 'binary'
end

#send_file(event) ⇒ Object



52
53
54
# File 'lib/log_sanity/log_subscribers/action_controller.rb', line 52

def send_file(event)
  log 'send_file', event.payload[:path]
end