Last active
August 26, 2015 21:06
-
-
Save dplummer/8278c630cdd51e10767c to your computer and use it in GitHub Desktop.
log silencer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
class Application < Rails::Application | |
require 'log_silencer' | |
config.middleware.insert_before Rails::Rack::Logger, | |
LogSilencer, | |
silenced: /^\/options/ | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/log_silencer.rb | |
class LogSilencer | |
def initialize(app, opts = {}) | |
@silenced = opts.delete(:silenced) | |
@app = app | |
end | |
def call(env) | |
if env['X-SILENCE-LOGGER'] || @silenced.match(env['PATH_INFO']) | |
Rails.logger.silence do | |
@app.call(env) | |
end | |
else | |
@app.call(env) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment