Sha256: a617018bfb01705868740ea3288daaac03afb6c6c924ba9ee30479d7ca9d74a2
Contents?: true
Size: 796 Bytes
Versions: 1
Compression:
Stored size: 796 Bytes
Contents
require 'rails/rack/logger' module Silencer class Logger < Rails::Rack::Logger def initialize(app, opts = {}) @app = app @opts = opts @opts[:silence] ||= [] end def call(env) if silence_request?(env) Rails.logger.silence do @app.call(env) end else super(env) end end private def silence_request?(env) silent_header?(env) || silent_request_path?(env) || silent_request_match?(env) end def silent_header?(env) env['X-SILENCE-LOGGER'] end def silent_request_path?(env) @opts[:silence].include?(env['PATH_INFO']) end def silent_request_match?(env) @opts[:silence].select {|s| s.kind_of?(Regexp) }.any? { |s| s =~ env['PATH_INFO']} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
silencer-0.1.0 | lib/silencer/logger.rb |