Class: Timber::Integrations::Rack::HTTPEvents
- Inherits:
-
Object
- Object
- Timber::Integrations::Rack::HTTPEvents
- Defined in:
- lib/timber/integrations/rack/http_events.rb
Overview
Reponsible for capturing and logging HTTP server requests and response events.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ HTTPEvents
constructor
A new instance of HTTPEvents.
Constructor Details
#initialize(app) ⇒ HTTPEvents
Returns a new instance of HTTPEvents.
6 7 8 |
# File 'lib/timber/integrations/rack/http_events.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/timber/integrations/rack/http_events.rb', line 10 def call(env) start = Time.now request = Util::Request.new(env) Config.instance.logger.info do Events::HTTPServerRequest.new( headers: request.headers, host: request.host, method: request.request_method, path: request.path, port: request.port, query_string: request.query_string, request_id: request.request_id, # we insert this middleware after ActionDispatch::RequestId scheme: request.scheme ) end status, headers, body = @app.call(env) Config.instance.logger.info do time_ms = (Time.now - start) * 1000.0 Events::HTTPServerResponse.new( headers: headers, request_id: request.request_id, status: status, time_ms: time_ms ) end [status, headers, body] end |