CakePHP error log - can I exclude 404 errors? -
the error log of cakephp app full of 404 errors. can exclude these missingcontrollerexceptions appearing in error log? using cake 2.3.
simply redirecting or removing these urls not going cut it.
a busy site hit hundreds of "random" 404s every day, far east countries checking exploits or urls such "/wp-admin".
logging these full stack trace unnecessary
solution
you can override default error handler in cakephp, , log app/tmp/logs/404.log instead.
in app/config/core.php file, define class want handle exceptions:
configure::write('error', array( 'handler' => 'mycustomerrorhandler::handleerror', 'level' => e_all & ~e_deprecated, 'trace' => true )); create class within app/lib/error , include using app::uses in app/config/bootstrap.php file:
app::uses('mycustomerrorhandler', 'lib/error'); make exact copy of original errorhandler class, change class name, , somewhere within handleexception method check exception being thrown, , log somewhere else. bit this;
app::uses('errorhandler', 'error'); class mycustomerrorhandler { public static function handleexception(exception $exception) { // code... if (in_array(get_class($exception), array('missingcontrollerexception', 'missingactionexception', 'privateactionexception', 'notfoundexception'))) { $log = '404'; $message = sprintf("[%s]", get_class($exception)); } // more code... } }
Comments
Post a Comment