2013-02-05 13:16:51 -06:00
|
|
|
class SilenceLogger < Rails::Rack::Logger
|
|
|
|
def initialize(app, opts = {})
|
|
|
|
@app = app
|
|
|
|
@opts = opts
|
|
|
|
@opts[:silenced] ||= []
|
2013-02-25 10:42:20 -06:00
|
|
|
|
|
|
|
# Rails introduces something called taggers in the Logger, needs to be initialized
|
2013-02-05 13:16:51 -06:00
|
|
|
super(app)
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
prev_level = Rails.logger.level
|
|
|
|
|
|
|
|
if env['HTTP_X_SILENCE_LOGGER'] || @opts[:silenced].include?(env['PATH_INFO'])
|
|
|
|
Rails.logger.level = Logger::WARN
|
|
|
|
result = @app.call(env)
|
|
|
|
result
|
|
|
|
else
|
|
|
|
super(env)
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Rails.logger.level = prev_level
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
silenced = ["/mini-profiler-resources/results", "/mini-profiler-resources/includes.js", "/mini-profiler-resources/includes.css", "/mini-profiler-resources/jquery.tmpl.js"]
|
2013-03-23 10:02:59 -05:00
|
|
|
Rails.configuration.middleware.swap Rails::Rack::Logger, SilenceLogger, silenced: silenced
|