我研究了不同的方法和指令,包括:
- 自动前置文件
- .user.ini 文件
- getcwd()
- 调试回溯()
我似乎找不到一种方法来更改 error_log 的路径以登录与包含/需要的文件相同的路径。
例如,假设 index.php 有以下行:
include('subdir/file.php');
If subdir/file.php
有语法错误,强制 php 创建subdir/error_log
,而不是在相同路径中创建 error_log 的默认行为index.php
、 auto_prepend_file 也受到同样的限制,因为它在调用的第一个脚本之前添加指定的文件,而不是包含的每个文件。
我环顾四周,似乎找不到合法的方法来做到这一点。我了解这样做对性能开销的影响,并计划仅将其用于开发目的。我相信这可以帮助隔离错误,而不是使用堆栈跟踪,例如debug_backtrace()
,因为我可以使用终端脚本来显示上次修改的最后一个错误日志,并且比阅读大量错误日志更快地找到有问题的文件。
显然,我的目标最终是根本不让这些文件出现,因为调试已经存在的站点并且必须查看 10GB 错误日志或tail
/multitail
它可能有点麻烦。我正在尝试设计这种方法,以便可以通过路径隔离错误。有什么建议么?
根据上面 hakre 的建议,我创建了这个脚本,将其包含在任何 php 脚本的顶部:
(如果您想分叉/下载它,这里还有我对此文件的要点:在 github 上查看 https://gist.github.com/uabassguy/6506245 )
<?
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');
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)