CodeIgniter Forums
Don't log 404 errors in error log - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Don't log 404 errors in error log (/showthread.php?tid=69498)



Don't log 404 errors in error log - mrtomtom - 12-04-2017

On our live site we get a lot of 404 errors from our site been probed by bots looking for phpMyAdmin/wordpress etc. This is filling up our log files with loads of  "404 Page Not Found: Phpmyadmin2015/index" etc.

What's the best way to stop any 404 errors being logged into our log files?

Many thanks!


RE: Don't log 404 errors in error log - mrtomtom - 12-07-2017

Not sure if my question is not clear or if it's just nobody knows?!


RE: Don't log 404 errors in error log - dave friend - 12-07-2017

I assume you are talking about the logs that CodeIgniter creates and not server or php logs.

Perhaps the least hackish way would be to extend the core class CI_Exceptions and override the method show_404. All the override has to do is call the parent method setting the second parameter to false.

The whole class definition is simple.

/application/core/MY_Exceptions.php

PHP Code:
class MY_Exceptions extends CI_Exceptions
{
 
    public function show_404($page ''$log_error TRUE)
    {
 
        parent::show_404($pageFALSE);
 
    }


The hack way to accomplish your goal is to modify CodeIgniter.php and change line 494 (version 3.1.6) from

PHP Code:
show_404($RTR->directory.$class.'/'.$method); 
to
PHP Code:
show_404($RTR->directory.$class.'/'.$methodFALSE); 



RE: Don't log 404 errors in error log - mrtomtom - 12-08-2017

Ah great idea to extend the exceptions. nice and clean.

Thanks!