In my CI config file I have this logging treshold set:
$config['log_threshold'] = 1;
In index.php, I have set the following error reporting:
error_reporting(E_ERROR);
My expectation is that this will log any CI errors that I log (using log_message('error','my error message')), as well as any PHP errors. However, I would expect that it will not log PHP notices, only errors. However, when I look at the log files, it seems to log PHP notices too:
ERROR – 2009-12-18 13:21:50—> Severity: Notice —> Undefined variable: pageindex /var/www/apps/OS4W/system/application/views/user/view.php 12
ERROR – 2009-12-18 13:21:50—> Severity: Notice —> Undefined variable: friendsmode /var/www/apps/OS4W/system/application/views/user/activitytable.php 207
Although the log lines start with “ERROR”, in reality this seems to be a PHP notice, kind of like a warning, that I do not want to log. How can I make sure only CI and PHP errors are logged, yet not PHP notices? I thought error_reporting(E_ERROR) would do just that?
First of all, thank you all for thinking along. After considering your advise, I decided to patch the core of CI. Unfortunately, the core classes can be extended, but not the core itself. Therefore if you apply the same patch, be sure to document it.
Here goes. In system\application\config\config.php I added the following custom config setting right below the log_treshold setting:
As the documentation explains, in this config array you put the PHP error types that you do NOT want to log.
Next, I have patched the core file (system/codeigniter/Common.php) and edited the function _exception_handler
There are two changes. First, I moved the config loading line to the top of the method, since I need it earlier. Find the line below and you will see $config =& get_config(); under it. Delete that.
I removed the // Should we log the error? No? We’re done…
Second, the check for severity is modified to check for the array that we declared. Go to the top of the method and replace the if statement that checks $severity == E_STRICT with below:
These patches allow for fine-grained control over PHP error logging. Normal CI logging will of course still work. As mentioned, the only downside is that this patches the core.
I hope this helps anyone. Thank you for thinking along!