blob: 91a613092fde657bf434f04ec320ee1c4e63e112 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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)
@env = env
before_dispatch
result = @app.call(@env)
after_dispatch
result
end
protected
def request
@request ||= ActionDispatch::Request.new(@env)
end
def before_dispatch
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
Rails::Subscriber.flush_all!
end
end
end
end
|