How to prevent logging of certain exception in rails
When there is no database connectivity to the application, I catch the ActiveRecord::RecordNotFound
exception in the rescue_action_in_public
method and try to render the page which doesn't have any database access.
When this happens, I dont want the Mysql:Error
exception to be logged, because for the whole period of DB down, this exception will be logged for each page access.
How can certain exceptions be prevented from bein开发者_如何学Pythong logged?
Try adding this in your application_controller.rb
:
EXCLUDED_EXCEPTIONS = ['ActiveRecord::RecordNotFound']
protected
def log_error(ex)
super unless EXCLUDED_EXCEPTIONS.include?(ex.class.name)
end
You can add additional exceptions to that array to exclude them as well.
精彩评论