Posted By

iloveitaly on 06/05/09


Tagged

php error function custom handle


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jschilling
Priestd09


Custom PHP Error Handler


 / Published in: PHP
 

  1. function logErrorsErrorHandler($errno, $errstr, $errfile, $errline) {
  2. switch ($errno) {
  3. case E_USER_ERROR:
  4. "<b>My ERROR</b> [$errno] $errstr<br />\n".
  5. " Fatal error on line $errline in file $errfile".
  6. ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n".
  7. "Aborting...<br />\n"
  8. );
  9. exit(1);
  10. break;
  11.  
  12. case E_WARNING:
  13. case E_USER_WARNING:
  14. error_log("<b>My WARNING</b> [$errno] $errstr<br />\n");
  15. break;
  16.  
  17. // case E_DEPRECATED:
  18. // case E_USER_DEPRECATED:
  19. case E_STRICT:
  20. break;
  21.  
  22. case E_USER_NOTICE:
  23. error_log("<b>My NOTICE</b> [$errno] $errstr<br />\n");
  24. break;
  25.  
  26. default:
  27. error_log("Unknown error type: [$errfile:$errline] [$errno] $errstr<br />\n");
  28. break;
  29. }
  30.  
  31. /* Don't execute PHP internal error handler */
  32. return true;
  33. }
  34.  
  35. ini_set('error_log', 'error_log');
  36. ini_set('log_errors', 'On');
  37.  
  38. set_error_handler("logErrorsErrorHandler");

Report this snippet  

You need to login to post a comment.