Skip to content

Instantly share code, notes, and snippets.

@uabassguy
Last active December 22, 2015 17:29
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 uabassguy/6506245 to your computer and use it in GitHub Desktop.
Save uabassguy/6506245 to your computer and use it in GitHub Desktop.
Custom error handler
<?
function custom_error_debug($errno, $errstr, $errfile, $errline, $errvars) {
$message = "";
$message .= "[ " . date('Y-m-d h-i-s') . " ] Error: [$errno] $errstr on line $errline of $errfile ";
//Dump all info to browser!
//WARNING: Leave this commented except for extreme cases where you need to see all variables in use!
//Using this will cause excessive processing time, and RAM. Use only as needed!
/*if (!empty($errvars)) {
echo $message . PHP_EOL . "Variables in use: <pre>";print_r($errvars); echo "</pre>";
//WARNING: not ending execution here may cause the browser to overload on larger frameworks, comment out at your own risk!
die();
}*/
//get the directory of the offending file, put a log in that path, and separate them by end of line, append to file
file_put_contents ( dirname($errfile) . "/php_errors.log", $message . PHP_EOL, FILE_APPEND );
//Dump all variables to file as well, (MAY CAUSE LARGE FILES, read above)
//file_put_contents ( dirname($errfile) . "/php_errors.log", $errvars . PHP_EOL, FILE_APPEND );
//Optionally end script execution
//die();
}
set_error_handler('custom_error_debug');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment