Class: Logjoy::LogSubscribers::ActionController

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/logjoy/log_subscribers/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



34
35
36
# File 'lib/logjoy/log_subscribers/action_controller.rb', line 34

def logger
  ::ActionController::Base.logger
end

#process_action(event) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/logjoy/log_subscribers/action_controller.rb', line 9

def process_action(event)
  return if ignore_event?(event)

  info do
    payload = event.payload

    log = payload.slice(:controller, :action, :format, :method, :status)
    log[:path] = strip_query(payload[:path])
    log[:view_runtime] = rounded_ms(payload[:view_runtime])
    log[:db_runtime] = rounded_ms(payload[:db_runtime])
    log[:duration] = rounded_ms(event.duration)
    log[:params] = cleanup_params(payload[:params])
    log[:request_id] = payload[:request].request_id
    log[:event] = event.name
    log[:allocations] = event.allocations

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

    log.merge(Logjoy.custom_fields(event)).to_json
  end
end