根据上面 hakre 的建议,我创建了这个脚本,包含在任何 php 脚本的顶部:
(如果你想分叉/下载它,这里也是我对这个文件的一个要点:在 github 上查看)
<?
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');
?>