Created
May 27, 2015 16:08
-
-
Save A35G/6ce7cae4260f6d89c973 to your computer and use it in GitHub Desktop.
Custom Script to manage Error Log in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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