Class: BufferingLogger::RailsRackLogRequestId

Inherits:
Object
  • Object
show all
Defined in:
lib/buffering_logger/rails_rack_log_request_id.rb

Overview

With buffered logs we don’t need to log the request_id on every line. Instead we log it once near the start of the request. We do this via a Rack middleware to ensure that it’s logged even for things like a ‘RoutingError` or other exceptional cases.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RailsRackLogRequestId

Returns a new instance of RailsRackLogRequestId.



9
10
11
# File 'lib/buffering_logger/rails_rack_log_request_id.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
# File 'lib/buffering_logger/rails_rack_log_request_id.rb', line 13

def call(env)
  request = ActionDispatch::Request.new(env)
  Rails.logger.info("request_id=#{request.request_id.inspect}")

  @app.call(env)
end