1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #44454 from jhawthorn/rack_logger_finish_with_state

Use finish_with_state inside Rack::Logger
This commit is contained in:
John Hawthorn 2022-02-24 15:24:55 -08:00 committed by GitHub
commit 0a44c3f90b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,13 +31,17 @@ module Rails
private
def call_app(request, env) # :doc:
instrumenter = ActiveSupport::Notifications.instrumenter
instrumenter.start "request.action_dispatch", request: request
instrumenter_state = instrumenter.start "request.action_dispatch", request: request
instrumenter_finish = -> () {
instrumenter.finish_with_state(instrumenter_state, "request.action_dispatch", request: request)
}
logger.info { started_request_message(request) }
status, headers, body = @app.call(env)
body = ::Rack::BodyProxy.new(body) { finish(request) }
body = ::Rack::BodyProxy.new(body, &instrumenter_finish)
[status, headers, body]
rescue Exception
finish(request)
instrumenter_finish.call
raise
ensure
ActiveSupport::LogSubscriber.flush_all!
@ -65,11 +69,6 @@ module Rails
end
end
def finish(request)
instrumenter = ActiveSupport::Notifications.instrumenter
instrumenter.finish "request.action_dispatch", request: request
end
def logger
Rails.logger
end