Sha256: 18e723c5538d374ef3c4a1338011598953744fce3a617987ef9782d81d6bf5f9

Contents?: true

Size: 595 Bytes

Versions: 2

Compression:

Stored size: 595 Bytes

Contents

require 'logger'

module Low
  module Middleware
    # `RequestLogger` sets 'rack.logger' to an instance of
    # `Low::ScopedLogger`, with `#level` and `#scope` taken from env.
    class RequestLogger

      def initialize(app, opts = {})
        @app = app
      end

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

      def logger(env)
        logger = Low::ScopedLogger.new(env['rack.errors'])
        logger.level = env['low.log_level'] || env['log_level']
        logger.scope = env['request_id']
        logger
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
low-0.0.12 lib/low/middleware/request_logger.rb
low-0.0.11 lib/low/middleware/request_logger.rb