Skip to content

Instantly share code, notes, and snippets.

@chrise86
Created May 26, 2012 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrise86/2792975 to your computer and use it in GitHub Desktop.
Save chrise86/2792975 to your computer and use it in GitHub Desktop.
A rails log silencer for specific calls / actions
# config/application.rb
require File.dirname(__FILE__) + '/../lib/custom_logger.rb'
module MyApp
class Application < Rails::Application
# Middlewares
config.middleware.swap Rails::Rack::Logger, CustomLogger, :silenced => ["/noisy/action.json"]
end
end
# lib/custom_logger.rb
class CustomLogger < Rails::Rack::Logger
def initialize(app, opts = {})
@app = app
@opts = opts
@opts[:silenced] ||= []
end
def call(env)
if env['X-SILENCE-LOGGER'] || @opts[:silenced].include?(env['PATH_INFO'])
Rails.logger.silence do
@app.call(env)
end
else
super(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment