I have this simple code in the first few lines of my script and it works real good in logging errors until I add the error handler function. My error handling function is doing quite a good job and I haven’t found any thing wrong with it expect this.
ini_set("log_errors" , "1");
ini_set("error_log" , $_SERVER['DOCUMENT_ROOT']."/logs/Errors.log.txt");
Is this thing a default working of php that error logging stops as soon as you start error handling?
If yes, how can I overcome it?
My error handler function might help to.
function userErrorHandler($errno, $errstr, $errfile = '', $errline = 0, $errcontext = array())
{
// Check if the error code is not included in error_reporting
if (!(error_reporting() & $errno))
{
return;
}
// Restore default handlers to prevent errors in errors
restore_error_handler();
if (function_exists('restore_exception_handler'))
{
restore_exception_handler();
}
// Load error page
require('_errors/error.php');
exit();
}
set_error_handler('userErrorHandler');
OK. So it overwrites default handler and the error logging stops, also their is no way to overcome that. But there is something else that can be done here and results the same output as expected.
The same that I wanted to do 🙂
Read the complete working here: http://blog.abhishekg.com/2012/06/error-handling-in-php-with-error-logger-working/