Class: Luna::Middleware::Verbose

Inherits:
Protocol::HTTP::Middleware
  • Object
show all
Defined in:
lib/luna/middleware/verbose.rb

Overview

Simple HTTP logging middleware adapted from Falcon.

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = Console) ⇒ Verbose

Returns a new instance of Verbose.



13
14
15
16
# File 'lib/luna/middleware/verbose.rb', line 13

def initialize(app, logger = Console)
	super(app)
	@logger = logger
end

Instance Method Details

#annotate(request) ⇒ Object



18
19
20
21
22
23
# File 'lib/luna/middleware/verbose.rb', line 18

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



25
26
27
28
29
30
31
32
33
# File 'lib/luna/middleware/verbose.rb', line 25

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
	response
end