Skip to content
This repository
Browse code

A patch so that http status codes are still included in logs even dur…

…ing an exception [#6333 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 56b6d7d9010e5db60aff5b682cab74d196829251 1 parent f156258
Doug Fales dougfales authored tenderlove committed
6 actionpack/lib/action_controller/log_subscriber.rb
@@ -16,7 +16,11 @@ def process_action(event)
16 16 payload = event.payload
17 17 additions = ActionController::Base.log_process_action(payload)
18 18
19   - message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration
  19 + status = payload[:status]
  20 + if status.nil? && payload[:exception].present?
  21 + status = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[payload[:exception].first]) rescue nil
  22 + end
  23 + message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration
20 24 message << " (#{additions.join(" | ")})" unless additions.blank?
21 25
22 26 info(message)
15 actionpack/test/controller/log_subscriber_test.rb
@@ -32,6 +32,11 @@ def with_page_cache
32 32 cache_page("Super soaker", "/index.html")
33 33 render :nothing => true
34 34 end
  35 +
  36 + def with_exception
  37 + raise Exception
  38 + end
  39 +
35 40 end
36 41 end
37 42
@@ -165,6 +170,16 @@ def test_with_page_cache
165 170 ensure
166 171 @controller.config.perform_caching = true
167 172 end
  173 +
  174 + def test_process_action_with_exception_includes_http_status_code
  175 + begin
  176 + get :with_exception
  177 + wait
  178 + rescue Exception => e
  179 + end
  180 + assert_equal 2, logs.size
  181 + assert_match(/Completed 500/, logs.last)
  182 + end
168 183
169 184 def logs
170 185 @logs ||= @logger.logged(:info)

0 comments on commit 56b6d7d

Please sign in to comment.
Something went wrong with that request. Please try again.