Jonathan Rochkind wrote:
Is there any easy way to tell Rails to keep [RoutingError, UnknownAction, UnknownController] out of my logs? Or
put them in a different log? Or at least omit the backtrace (which is
not a useful backtrace, since it's to Rails internals and is always the
same for an UnknownAction or RoutingError).
By the time rescue_action_in_public is called, it seems to be too late,
the thing has already been logged.
Figured it out myself looking at source in ActionController::rescue.rb .
I'll put it here for the archives.
In Rails 2.1 (and hopefully 2.x in general), rescue_action_in_public is
called by rescue_action.
rescue_action also calls log_error, after calling
It's log_error that writes uncaught exceptions to the log as fatal, with
So I can override log_error, and check the class of the error. If it's
not a routing type error, call super. If it is, I can not log it, log it
to a different logger, log it with a different severity, whatever.