开发者

How to prevent logging of certain exception in rails

开发者 https://www.devze.com 2023-01-21 16:47 出处:网络
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 d

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消