Juraj Ivan
Juraj Ivan

Reputation: 493

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.

Upvotes: 8

Views: 2411

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84162

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

Upvotes: 19

Related Questions