Class: ActionController::LogSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/time_bandits/monkey_patches/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#process_action(event) ⇒ Object

the original method logs the completed line. but we do it in the middleware, unless we’re in test mode. don’t ask.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/time_bandits/monkey_patches/action_controller.rb', line 96

def process_action(event)
  payload   = event.payload
  additions = ActionController::Base.log_process_action(payload)

  Thread.current.thread_variable_set(
    :time_bandits_completed_info,
    [ event.duration, additions, payload[:view_runtime], "#{payload[:controller]}##{payload[:action]}" ]
  )

  # this is an ugly hack to ensure completed lines show up in the test logs
  # TODO: move this code to some other place
  return unless Rails.env.test? && Rails::VERSION::STRING >= "3.2"

  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
  message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % event.duration
  message << " (#{additions.join(" | ")})" unless additions.blank?

  info(message)
end