class ApiValve::Middleware::Logging

Public Class Methods

new(app) click to toggle source
# File lib/api_valve/middleware/logging.rb, line 105
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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