提交 7927fc2f 编写于 作者: D Doug Fales 提交者: José Valim

A patch so that http status codes are still included in logs even during an...

A patch so that http status codes are still included in logs even during an exception [#6333 state:resolved]
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 59f32184
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册