Sha256: c547f14ddac6049a4951b78b15e3f3b25324896bf0a17cf8daa3f28a31901aba

Contents?: true

Size: 626 Bytes

Versions: 1

Compression:

Stored size: 626 Bytes

Contents

require 'rails/rack/logger'
require 'active_support/core_ext/array/wrap'

module Silencer
  class Logger < Rails::Rack::Logger
    def initialize(app, opts = {})
      @app = app
      @silence = Array.wrap(opts[:silence])
    end

    def call(env)
      old_logger_level   = Rails.logger.level
      Rails.logger.level = ::Logger::ERROR if silence_request?(env)

      super
    ensure
      # Return back to previous logging level
      Rails.logger.level = old_logger_level
    end

    private

    def silence_request?(env)
      env['X-SILENCE-LOGGER'] || @silence.any? { |s| s === env['PATH_INFO'] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
silencer-0.3.0 lib/silencer/logger.rb