Skip to content

Instantly share code, notes, and snippets.

@dplummer
Last active August 26, 2015 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dplummer/8278c630cdd51e10767c to your computer and use it in GitHub Desktop.
Save dplummer/8278c630cdd51e10767c to your computer and use it in GitHub Desktop.
log silencer
# config/application.rb
class Application < Rails::Application
require 'log_silencer'
config.middleware.insert_before Rails::Rack::Logger,
LogSilencer,
silenced: /^\/options/
end
# 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