Class: Falcon::Middleware::Verbose
- Inherits:
-
Protocol::HTTP::Middleware
- Object
- Protocol::HTTP::Middleware
- Falcon::Middleware::Verbose
- Defined in:
- lib/falcon/middleware/verbose.rb
Overview
A HTTP middleware for logging requests and responses.
Instance Method Summary collapse
-
#annotate(request) ⇒ Object
Log details of the incoming request.
-
#call(request) ⇒ Object
Log details of the incoming request using #annotate and wrap the response to log response details too.
-
#initialize(app, logger = Console) ⇒ Verbose
constructor
Initialize the verbose middleware.
Constructor Details
#initialize(app, logger = Console) ⇒ Verbose
Initialize the verbose middleware.
16 17 18 19 20 |
# File 'lib/falcon/middleware/verbose.rb', line 16 def initialize(app, logger = Console) super(app) @logger = logger end |
Instance Method Details
#annotate(request) ⇒ Object
Log details of the incoming request.
23 24 25 26 27 28 29 30 |
# File 'lib/falcon/middleware/verbose.rb', line 23 def annotate(request) task = Async::Task.current address = request.remote_address @logger.info(request, "-> #{request.method} #{request.path}", headers: request.headers.to_h, address: address.inspect) task.annotate("#{request.method} #{request.path} from #{address.inspect}") end |
#call(request) ⇒ Object
Log details of the incoming request using #annotate and wrap the response to log response details too.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/falcon/middleware/verbose.rb', line 33 def call(request) annotate(request) statistics = Async::HTTP::Statistics.start response = super statistics.wrap(response) do |body, error| @logger.info(request, "<- #{request.method} #{request.path}", headers: response.headers.to_h, status: response.status, body: body.inspect, error: error) end return response end |