diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-09 15:34:36 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-09 15:34:58 -0800 |
commit | ffa9540fd361eb34c445568b66abf283b9e658f8 (patch) | |
tree | 18ba3d287644671c560985c29899b71a8a17b624 /railties/lib | |
parent | 8ae9b4623e16f28c7954edcd89fbab2bba99b334 (diff) | |
download | rails-ffa9540fd361eb34c445568b66abf283b9e658f8.tar.gz rails-ffa9540fd361eb34c445568b66abf283b9e658f8.tar.bz2 rails-ffa9540fd361eb34c445568b66abf283b9e658f8.zip |
fire a notification when the request stops / starts
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/rack/logger.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 78b4e68ce4..6ed6722c44 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -1,12 +1,17 @@ require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/object/blank' +require 'active_support/log_subscriber' +require 'action_dispatch/http/request' +require 'rack/body_proxy' module Rails module Rack # Sets log tags, logs the request, calls the app, and flushes the logs. class Logger < ActiveSupport::LogSubscriber def initialize(app, taggers = nil) - @app, @taggers = app, taggers || [] + @app = app + @taggers = taggers || [] + @instrumenter = ActiveSupport::Notifications.instrumenter end def call(env) @@ -28,8 +33,14 @@ module Rails logger.debug '' end + @instrumenter.start 'action_dispatch.request', request: request logger.info started_request_message(request) - @app.call(env) + resp = @app.call(env) + resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) } + resp + rescue + finish(request) + raise ensure ActiveSupport::LogSubscriber.flush_all! end @@ -58,6 +69,10 @@ module Rails private + def finish(request) + @instrumenter.finish 'action_dispatch.request', request: request + end + def development? Rails.env.development? end |