Class: RequestIdLogging::Middleware
- Inherits:
-
Object
- Object
- RequestIdLogging::Middleware
- Defined in:
- lib/request_id_logging/middleware.rb
Overview
Rack middleware for logging with request_id.
Please insert after ActionDispatch::RequestId in your application.rb like as follows.
module YourApp
class Application < Rails::Application
# some configurations...
config.middleware.insert_after ActionDispatch::RequestId, RequestIdLogging::Middleware
end
end
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
18 19 20 |
# File 'lib/request_id_logging/middleware.rb', line 18 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/request_id_logging/middleware.rb', line 22 def call(env) request_id = env['action_dispatch.request_id'] Thread.current[RequestIdLogging::FIBER_LOCAL_KEY] = request_id @app.call(env) ensure Thread.current[RequestIdLogging::FIBER_LOCAL_KEY] = nil end |