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

35 lines
760 B
Ruby
Raw Normal View History

2010-01-21 07:05:30 -05:00
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)
2010-01-26 09:37:45 -05:00
before_dispatch(env)
@app.call(env)
ensure
after_dispatch(env)
2010-01-21 07:05:30 -05:00
end
protected
2010-01-26 09:37:45 -05:00
def before_dispatch(env)
request = ActionDispatch::Request.new(env)
2010-01-21 07:05:30 -05:00
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
2010-01-26 09:37:45 -05:00
def after_dispatch(env)
2010-01-21 07:05:30 -05:00
Rails::Subscriber.flush_all!
end
end
end
end