Class: Lennarb::Middleware::RequestLogger
- Inherits:
-
Object
- Object
- Lennarb::Middleware::RequestLogger
- Defined in:
- lib/lennarb/middleware/request_logger.rb
Overview
Request logger for the Lennarb framework Logs HTTP request details with color formatting
Instance Method Summary collapse
-
#call(env) ⇒ Array
Process the request and log information.
-
#initialize(app) ⇒ RequestLogger
constructor
A new instance of RequestLogger.
-
#logger(env = nil) ⇒ Object
Get the logger for this request.
Constructor Details
#initialize(app) ⇒ RequestLogger
Returns a new instance of RequestLogger.
12 13 14 |
# File 'lib/lennarb/middleware/request_logger.rb', line 12 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Array
Process the request and log information
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lennarb/middleware/request_logger.rb', line 32 def call(env) request = Lennarb::Request.new(env) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) status, headers, body = @app.call(env) duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time log_request(request, status, headers, duration, env) [status, headers, body] end |
#logger(env = nil) ⇒ Object
Get the logger for this request.
Resolved from the app handling the request, which App#call publishes in the Rack env, so an app's configured logger is actually used. Falls back to the class-level default when there is no app in the env.
24 25 26 |
# File 'lib/lennarb/middleware/request_logger.rb', line 24 def logger(env = nil) env&.[](RACK_LENNA_APP)&.config&.logger || Lennarb::App.app.config.logger end |