Skip to content

Instantly share code, notes, and snippets.

@A35G
Created May 27, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A35G/6ce7cae4260f6d89c973 to your computer and use it in GitHub Desktop.
Save A35G/6ce7cae4260f6d89c973 to your computer and use it in GitHub Desktop.
Custom Script to manage Error Log in PHP
<?php
function customErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno))
return true;
switch ($errno) {
case E_USER_ERROR:
echo "[client ".$_SERVER['REMOTE_ADDR']."] ERROR: [".$errno."] ".$errstr." on line ".$errline." in file ".$errfile." ";
exit(1);
break;
case E_USER_WARNING:
case E_USER_NOTICE:
default:
echo "[client ".$_SERVER['REMOTE_ADDR']."] ERROR: [".$errno."] ".$errstr." on line ".$errline." in file ".$errfile." ";
break;
}
error_log("[$errno] $errstr", 0);
return true;
}
function fatalErrorHandler() {
$last_error = error_get_last();
if ($last_error['type'] === E_ERROR)
customErrorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
}
register_shutdown_function('fatalErrorHandler');
set_error_handler("customErrorHandler", E_ALL|E_NOTICE|E_STRICT|E_DEPRECATED);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment