Created
May 26, 2012 08:53
-
-
Save chrise86/2792975 to your computer and use it in GitHub Desktop.
A rails log silencer for specific calls / actions
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 | |
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 |
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/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