Class: Low::Rack::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/low/rack/request_logger.rb

Overview

‘RequestLogger` sets ’rack.logger’ to an instance of ‘Low::ScopedLogger`, with `#level` and `#scope` taken from env.

Constant Summary collapse

DEFAULT_KEY =
'rack.logger'

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ RequestLogger

Returns a new instance of RequestLogger.



13
14
15
16
# File 'lib/low/rack/request_logger.rb', line 13

def initialize(app, opts = {})
  @app = app
  @key = opts[:key] || Low::Rack::Default::LOGGER_KEY
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
# File 'lib/low/rack/request_logger.rb', line 18

def call(env)
  env[@key] = logger(env)
  @app.call(env)
end

#logger(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/low/rack/request_logger.rb', line 23

def logger(env)
  logger = Low::ScopedLogger.new(env['rack.errors'])

  if level = env['low.log_level'] || env['log_level']
    logger.level = level
  end

  logger.scope = env['request_id']
  logger
end