Skip to content

Commit

Permalink
A patch so that http status codes are still included in logs even dur…
Browse files Browse the repository at this point in the history
…ing an exception [#6333 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
dougfales authored and josevalim committed Jan 25, 2011
1 parent 59f3218 commit 7927fc2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion actionpack/lib/action_controller/log_subscriber.rb
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions actionpack/test/controller/log_subscriber_test.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

2 comments on commit 7927fc2

@qrush
Copy link
Contributor

@qrush qrush commented on 7927fc2 Jan 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@npj
Copy link

@npj npj commented on 7927fc2 May 13, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+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.