Sha256: 7311f04caacabf2ecc4bc813909c93dfc2f312122bd10b30c595a880b9fa87b5
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
module Superlogger class ActionControllerLogSubscriber < ActiveSupport::LogSubscriber INTERNAL_PARAMS = %w(controller action format _method only_path) # start of controller action def start_processing(event) payload = event.payload Logger.debug controller: payload[:controller], action: payload[:action], params: payload[:params].except(*INTERNAL_PARAMS) end # end of controller action def process_action(event) payload = event.payload if payload[:exception] status = ActionDispatch::ExceptionWrapper.status_code_for_exception(payload[:exception][0]) Logger.fatal status: status, exception: payload[:exception] else # Assume status 401 if action finishes without status code and no exception # https://github.com/pcg79/devise/commit/1e2dab3c0ce49efe2b5940c15f47388c69d6731b payload[:status] ||= 401 total_duration = event.duration.to_f.round(2) 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) Logger.info status: payload[:status], total_duration: total_duration, view_duration: view_duration, db_duration: db_duration end end end end Superlogger::ActionControllerLogSubscriber.attach_to :action_controller
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
superlogger-0.0.2 | lib/superlogger/action_controller_log_subscriber.rb |
superlogger-0.0.1 | lib/superlogger/action_controller_log_subscriber.rb |