Class: GreenLog::Rack::RequestLogging
- Inherits:
-
Object
- Object
- GreenLog::Rack::RequestLogging
- Defined in:
- lib/green_log/rack/request_logging.rb
Overview
Structured request logging.
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, logger, log_request_bodies: false) ⇒ RequestLogging
constructor
A new instance of RequestLogging.
Constructor Details
#initialize(app, logger, log_request_bodies: false) ⇒ RequestLogging
Returns a new instance of RequestLogging.
12 13 14 15 16 |
# File 'lib/green_log/rack/request_logging.rb', line 12 def initialize(app, logger, log_request_bodies: false) @app = app @logger = logger @log_request_bodies = log_request_bodies end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/green_log/rack/request_logging.rb', line 18 def call(env) started_at = Time.now status, headers, _body = @app.call(env) ensure status ||= 500 headers ||= {} duration = Time.now - started_at log( request: ::Rack::Request.new(env), response: Response.new(status, headers, duration), ) end |