Class: LogSanity::LogSubscriber::ActionDispatch

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

Instance Method Summary collapse

Instance Method Details

#redirect(event) ⇒ Object



44
45
46
# File 'lib/log_sanity/log_subscribers/action_dispatch.rb', line 44

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

#request(event) ⇒ Object



5
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
# File 'lib/log_sanity/log_subscribers/action_dispatch.rb', line 5

def request(event)
  payload = event.payload
  return if payload[:silence]

  info do
    request = payload[:request]
    response = payload[:response]
    method = payload[:method] || (request.request_method rescue nil) || 'UNKNOWN'
    f2 = {
      'at' => event_start(event),
      'event' => "#{request.scheme}_#{method.downcase}",
      'ip' => request.remote_ip,
      'rq' => request.uuid,
      # 'path' => request.path,           # path only
      # 'path' => request.filtered_path,  # path + params
      # 'params' => request.filtered_parameters,
    }

    unless fields['route']
      unless fields['path']
        # most errors repopulate path, so look for the original one first.
        # original_path is, however, unfiltered.
        f2['path']   = request.filtered_env['action_dispatch.original_path']
        f2['path'] ||= request.path
      end
      if !fields['params'] && p2 = request.filtered_parameters.presence
        f2['params'] = p2
      end
    end

    fields['duration'] ||= {}
    fields['duration']['total'] = event.duration.round
      # rewrites 'total', which includes more of time spent in middleware
    fields['status'] ||= response[0].to_i if response
    compute_tags(request)
    f2.merge fields
  end
end