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.logger)  ⇒ Verbose 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Initialize the verbose middleware.
 
Constructor Details
#initialize(app, logger = Console.logger) ⇒ Verbose
Initialize the verbose middleware.
      33 34 35 36 37  | 
    
      # File 'lib/falcon/middleware/verbose.rb', line 33 def initialize(app, logger = Console.logger) super(app) @logger = logger end  | 
  
Instance Method Details
#annotate(request) ⇒ Object
Log details of the incoming request.
      40 41 42 43 44 45 46 47  | 
    
      # 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) ⇒ Object
Log details of the incoming request using #annotate and wrap the response to log response details too.
      50 51 52 53 54 55 56 57 58 59 60 61 62 63 64  | 
    
      # 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.}"} if error end return response end  |