Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 7927fc2ff77543a0ab151ac1cb3d60318e2dfa68 1 parent 59f3218
@dougfales dougfales authored josevalim committed
View
6 actionpack/lib/action_controller/log_subscriber.rb
@@ -16,7 +16,11 @@ def process_action(event)
payload = event.payload
additions = ActionController::Base.log_process_action(payload)
- message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration
+ status = payload[:status]
+ if status.nil? && payload[:exception].present?
+ status = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[payload[:exception].first]) rescue nil
+ end
+ message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration
message << " (#{additions.join(" | ")})" unless additions.blank?
info(message)
View
15 actionpack/test/controller/log_subscriber_test.rb
@@ -32,6 +32,11 @@ def with_page_cache
cache_page("Super soaker", "/index.html")
render :nothing => true
end
+
+ def with_exception
+ raise Exception
+ end
+
end
end
@@ -168,6 +173,16 @@ def test_with_page_cache
ensure
@controller.config.perform_caching = true
end
+
+ def test_process_action_with_exception_includes_http_status_code
+ begin
+ get :with_exception
+ wait
+ rescue Exception => e
+ end
+ assert_equal 2, logs.size
+ assert_match(/Completed 500/, logs.last)
+ end
def logs
@logs ||= @logger.logged(:info)

2 comments on commit 7927fc2

@qrush

+1000. this has really messed me up a serious amount, I would love to see a patch release with this soon.

@npj

+1. Any possibility of a pre-3.1 patch for this issue? I'd love to see some error status codes in my logs!

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