【发布时间】:2011-12-29 04:03:11
【问题描述】:
我正在尝试禁用在文件中显示错误并将它们记录到日志文件中
<?php
error_reporting('E_ALL');
echo $x;
?>
当我删除 error_reporting('E_ALL') 时日志文件有效,但随后也会显示错误。 是否有其他方法可以做到这一点,但仅在特定页面上禁用错误报告。
【问题讨论】:
标签: php error-reporting
我正在尝试禁用在文件中显示错误并将它们记录到日志文件中
<?php
error_reporting('E_ALL');
echo $x;
?>
当我删除 error_reporting('E_ALL') 时日志文件有效,但随后也会显示错误。 是否有其他方法可以做到这一点,但仅在特定页面上禁用错误报告。
【问题讨论】:
标签: php error-reporting
您可以创建自定义错误处理函数并通过set_error_handler()进行设置:
set_error_handler(function($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null)
{
// Append $errstr and other useful information to a file
@file_put_contents('error_log', "ERROR: $errstr\n", FILE_APPEND);
return true; // disable regular PHP error reporting
});
【讨论】:
【讨论】: