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?
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
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/}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With