Class: Superlogger::ActionControllerLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/superlogger/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

end of controller action



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/superlogger/action_controller_log_subscriber.rb', line 12

def process_action(event)
  payload = event.payload
  view_duration  = payload[:view_runtime].to_f.round(2) if payload.key?(:view_runtime)
  db_duration    = payload[:db_runtime].to_f.round(2) if payload.key?(:db_runtime)

  if payload[:exception]
    logger.fatal view_duration: view_duration, db_duration: db_duration, exception: payload[:exception]
  else
    logger.info view_duration: view_duration, db_duration: db_duration
  end
end

#start_processing(event) ⇒ Object

start of controller action



6
7
8
9
# File 'lib/superlogger/action_controller_log_subscriber.rb', line 6

def start_processing(event)
  payload = event.payload
  logger.debug {{ controller: payload[:controller], action: payload[:action], params: payload[:params].except(*INTERNAL_PARAMS) }}
end