Class: Falcon::Verbose
- Inherits:
-
Object
- Object
- Falcon::Verbose
- Defined in:
- lib/falcon/verbose.rb
Instance Method Summary collapse
- #annotate(env, task = Async::Task.current) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, logger = Async.logger) ⇒ Verbose
constructor
A new instance of Verbose.
- #log(start_time, env, response, error) ⇒ Object
Constructor Details
#initialize(app, logger = Async.logger) ⇒ Verbose
25 26 27 28 |
# File 'lib/falcon/verbose.rb', line 25 def initialize(app, logger = Async.logger) @app = app @logger = logger end |
Instance Method Details
#annotate(env, task = Async::Task.current) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/falcon/verbose.rb', line 30 def annotate(env, task = Async::Task.current) request_method = env['REQUEST_METHOD'] request_path = env['PATH_INFO'] remote_address = env['REMOTE_ADDR'] task.annotate("#{request_method} #{request_path} for #{remote_address}") end |
#call(env) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/falcon/verbose.rb', line 52 def call(env) start_time = Time.now annotate(env) response = @app.call(env) ensure log(start_time, env, response, $!) end |
#log(start_time, env, response, error) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/falcon/verbose.rb', line 38 def log(start_time, env, response, error) duration = Time.now - start_time request_method = env['REQUEST_METHOD'] request_path = env['PATH_INFO'] if response status, headers, body = response @logger.info "#{request_method} #{request_path} -> #{status}; Content length #{headers.fetch('Content-Length', '-')} bytes; took #{duration} seconds" else @logger.info "#{request_method} #{request_path} -> #{error}; took #{duration} seconds" end end |