Skip to content

Instantly share code, notes, and snippets.

@lsd
Created January 30, 2013 23:56
Show Gist options
  • Save lsd/4678535 to your computer and use it in GitHub Desktop.
Save lsd/4678535 to your computer and use it in GitHub Desktop.
backtrace_silencer.rb code to discard RoutingErrors from the logs
# Place me in <app>/config/initializers/backtrace_silencer.rb
# Be sure to restart your server when you modify this file.
# No more RoutingError exceptions clogging your logs.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
# This is responsible for logging exceptions/showing debugging page if request is local.
# Let's use it to make 404 exceptions inconspicuous rather than silence completely
class ActionDispatch::DebugExceptions
alias_method :orig_log_error, :log_error
def log_error(env, wrapper)
if wrapper.exception.is_a? ActionController::RoutingError
else
orig_log_error env, wrapper
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment