diff options
author | Doug Fales <doug@getharvest.com> | 2011-01-18 15:36:08 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-01-25 20:12:22 +0100 |
commit | 7927fc2ff77543a0ab151ac1cb3d60318e2dfa68 (patch) | |
tree | f71557b6757a43e05852cb5a3bbe6886d0e3a88b | |
parent | 59f3218463228ca2301857cd7bf4f82f308924a6 (diff) | |
download | rails-7927fc2ff77543a0ab151ac1cb3d60318e2dfa68.tar.gz rails-7927fc2ff77543a0ab151ac1cb3d60318e2dfa68.tar.bz2 rails-7927fc2ff77543a0ab151ac1cb3d60318e2dfa68.zip |
A patch so that http status codes are still included in logs even during an exception [#6333 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r-- | actionpack/lib/action_controller/log_subscriber.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/log_subscriber_test.rb | 15 |
2 files changed, 20 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb index 3b19310a69..3fae697cc3 100644 --- a/actionpack/lib/action_controller/log_subscriber.rb +++ b/actionpack/lib/action_controller/log_subscriber.rb @@ -16,7 +16,11 @@ module ActionController 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) diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index cac0881133..21bbd83653 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -32,6 +32,11 @@ module Another cache_page("Super soaker", "/index.html") render :nothing => true end + + def with_exception + raise Exception + end + end end @@ -168,6 +173,16 @@ class ACLogSubscriberTest < ActionController::TestCase 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) |