Class: ApiValve::Middleware::Logging
- Inherits:
-
Object
- Object
- ApiValve::Middleware::Logging
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/api_valve/middleware/logging.rb
Defined Under Namespace
Classes: Log
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Logging
constructor
A new instance of Logging.
Constructor Details
#initialize(app) ⇒ Logging
Returns a new instance of Logging.
105 106 107 |
# File 'lib/api_valve/middleware/logging.rb', line 105 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/api_valve/middleware/logging.rb', line 109 def call(env) env['rack.logger'] = ApiValve.logger env['rack.errors'] = ApiValve.logger ApiValve.logger.tagged(Thread.current[:request_id]) do log = Log.new(began_at: Time.now, env: env) log.before_request status, headers, body = @app.call(env) log.assign status: status, response_headers: headers, response_payload: body log.after_request [status, headers, body] end end |