aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/rails/rack/logger.rb
blob: de21fb4f101e1f2c37e6c5dd2c878de9bf9625ca (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                             



                            



               

                                                    





                                                                         
                               





                                      
require 'rails/subscriber'

module Rails
  module Rack
    # Log the request started and flush all loggers after it.
    class Logger < Rails::Subscriber
      def initialize(app)
        @app = app
      end

      def call(env)
        before_dispatch(env)
        @app.call(env)
      ensure
        after_dispatch(env)
      end

      protected

        def before_dispatch(env)
          request = ActionDispatch::Request.new(env)
          path = request.request_uri.inspect rescue "unknown"

          info "\n\nStarted #{request.method.to_s.upcase} #{path} " <<
                      "for #{request.remote_ip} at #{Time.now.to_s(:db)}"
        end

        def after_dispatch(env)
          Rails::Subscriber.flush_all!
        end

    end
  end
end