class Falcon::Middleware::Verbose

A HTTP middleware for logging requests and responses.

Public Class Methods

new(app, logger = Console.logger) click to toggle source

Initialize the verbose middleware. @parameter app [Protocol::HTTP::Middleware] The middleware to wrap. @parameter logger [Console::Logger] The logger to use.

Calls superclass method
# File lib/falcon/middleware/verbose.rb, line 33
def initialize(app, logger = Console.logger)
        super(app)
        
        @logger = logger
end

Public Instance Methods

annotate(request) click to toggle source

Log details of the incoming request.

# File lib/falcon/middleware/verbose.rb, line 40
def annotate(request)
        task = Async::Task.current
        address = request.remote_address
        
        @logger.info(request) {"Headers: #{request.headers.to_h} from #{address.inspect}"}
        
        task.annotate("#{request.method} #{request.path} from #{address.inspect}")
end
call(request) click to toggle source

Log details of the incoming request using {annotate} and wrap the response to log response details too.

Calls superclass method
# File lib/falcon/middleware/verbose.rb, line 50
def call(request)
        annotate(request)
        
        statistics = Async::HTTP::Statistics.start
        
        response = super
        
        statistics.wrap(response) do |statistics, error|
                @logger.info(request) {"Responding with: #{response.status} #{response.headers.to_h}; #{statistics.inspect}"}
                
                @logger.error(request) {"#{error.class}: #{error.message}"} if error
        end
        
        return response
end