Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created March 14, 2012 14:33
Show Gist options
  • Save ahoward/2036895 to your computer and use it in GitHub Desktop.
Save ahoward/2036895 to your computer and use it in GitHub Desktop.
config/initializers/silenceable_logger.rb
# inspired by : http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/
#
# file: ./config/initializers/silenceable_logger.rb
#
# then, in some crazy js polling action use
#
# ajax('/poll?silence=logger')
#
Rails::Rack::Logger.class_eval do
def call_with_silenced_logger(env)
if env['QUERY_STRING'] =~ /silence=logger/iomx
begin
a = Rails.logger.level
b = ActionController::Base.logger.level
Rails.logger.level = :fatal
ActionController::Base.logger.level = :fatal
call_without_silenced_logger(env)
ensure
Rails.logger.level = a
ActionController::Base.logger.level = b
end
else
call_without_silenced_logger(env)
end
end
alias_method_chain(:call, :silenced_logger)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment