Class: Falcon::Verbose

Inherits:
Async::HTTP::Middleware
  • Object
show all
Defined in:
lib/falcon/verbose.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = Async.logger) ⇒ Verbose

Returns a new instance of Verbose.



26
27
28
29
30
# File 'lib/falcon/verbose.rb', line 26

def initialize(app, logger = Async.logger)
  super(app)
  
  @logger = logger
end

Instance Method Details

#annotate(request) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/falcon/verbose.rb', line 32

def annotate(request)
  task = Async::Task.current
  address = request.remote_address
  
  @logger.debug(request.authority) {"#{request.method} #{request.path} #{request.version} from #{address.inspect}"}
  # @logger.debug(request.authority) {request.headers.inspect}
  
  task.annotate("#{request.method} #{request.path} from #{address.inspect}")
end

#call(request) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/falcon/verbose.rb', line 42

def call(request)
  annotate(request)
  
  statistics = Async::HTTP::Statistics.start
  
  response = super
  
  statistics.wrap(response) do |statistics, error|
    @logger.info(request.authority) {"#{request.method} #{request.path} #{request.version} -> #{response.status}; #{statistics.inspect}"}
    # @logger.info response.headers.inspect
    @logger.error(request.authority) {"#{error.class}: #{error.message}"} if error
  end
  
  return response
end