Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop logging ActionController::RoutingError Rails 3.2

How to disable logging for ActionController::RoutingError Errors?
My production log file is full of bots searching for phpMyAdmin and other stuff.
Then the real application errors are overlooked.
Please help. I'm running Rails 3.2 and Passenger.

In my routes.rb I map all other urls to get ":code" => "shared#code", and then, if not found, i display a page with message. But when the bot search for urls like http://mywebsite.com/phpMyAdmin/index.php, the classic error page is shown "The page you were looking for doesn't exist.". Which is ok. But i just dont want to log these errors in the log file.

like image 459
Juraj Ivan Avatar asked Sep 01 '12 12:09

Juraj Ivan


1 Answers

The thing that logs/displays errors is the ActionDispatch::DebugExceptions middleware. You could just overwrite the log_error method, for example stick this in an initialiser:

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
like image 165
Frederick Cheung Avatar answered Sep 28 '22 08:09

Frederick Cheung