Class: Cogger::Rack::Logger
- Inherits:
-
Object
- Object
- Cogger::Rack::Logger
- Defined in:
- lib/cogger/rack/logger.rb
Overview
Middlware for enriched logging based on the incoming request.
Constant Summary collapse
- DEFAULTS =
{ logger: Cogger.new(formatter: :json), timer: Cogger::Time::Span.new, key_map: { verb: "REQUEST_METHOD", ip: "REMOTE_ADDR", path: "PATH_INFO", params: "QUERY_STRING", length: "CONTENT_LENGTH" } }.freeze
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(application, options = Core::EMPTY_HASH, defaults: DEFAULTS) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(application, options = Core::EMPTY_HASH, defaults: DEFAULTS) ⇒ Logger
Returns a new instance of Logger.
21 22 23 24 25 26 27 28 |
# File 'lib/cogger/rack/logger.rb', line 21 def initialize application, = Core::EMPTY_HASH, defaults: DEFAULTS configuration = defaults.merge @application = application @logger = configuration.fetch :logger @timer = configuration.fetch :timer @key_map = configuration.fetch :key_map end |
Instance Method Details
#call(environment) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/cogger/rack/logger.rb', line 30 def call environment request = ::Rack::Request.new environment (status, headers, body), duration, unit = timer.call { application.call environment } logger.info tags: [(request), {status:, duration:, unit:}] [status, headers, body] end |