Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide ActionController::RoutingError in logs for assets

I am working on a rails app that has a WP home page, and also some images that are being load from WP. On localhost we don't have access to WP content that leads to having a lot of routing errors in logs, in example:

Started GET "/wp-content/uploads/2014/03/facebook-icon1.png" for 127.0.0.1 at 2015-11-20 15:10:48 +0200

ActionController::RoutingError (No route matches [GET] "/wp-content/uploads/2014/03/facebook-icon1.png"):
  actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'

Considering we have 5 images on the page we end up having 5 routing errors for each request. How can I hide these type of errors from logs in dev environment?

like image 866
rmagnum2002 Avatar asked Dec 05 '22 01:12

rmagnum2002


2 Answers

Had this exact problem. Create a logger.rb file in your initializers folder and add this code:

# spammers were blowing up our logs
# this suppresses routing errors
if Rails.env.production?
    class ActionDispatch::DebugExceptions
      alias_method :old_log_error, :log_error
      def log_error(env, wrapper)
        if wrapper.exception.is_a?  ActionController::RoutingError
          return
        else
          old_log_error env, wrapper
        end
      end
    end
end
like image 143
Joshua Avatar answered Dec 21 '22 22:12

Joshua


Maybe this silencer gem can help you.

Usage:

In your environment:

require 'silencer/logger'

config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => [%r{^/wp-content/}]
like image 38
dinglixiang Avatar answered Dec 22 '22 00:12

dinglixiang