记录php错误,但不在浏览器中显示

记录php错误,但不在浏览器中显示,php,error-handling,Php,Error Handling,我想创建错误日志,但不想在浏览器中显示它 当前,当发生错误或警告/通知时,会创建日志并向浏览器显示错误,但我想强制系统不要在浏览器中向站点访问者显示错误消息,而是为我创建日志 谢谢可以试试 error_reporting(E_ERROR | E_PARSE); 确保php.ini中有类似的内容: display_errors = Off error_log = /var/log/php/error.log # Assuming you have /var/log/php directory a

我想创建错误日志,但不想在浏览器中显示它

当前,当发生错误或警告/通知时,会创建日志并向浏览器显示错误,但我想强制系统不要在浏览器中向站点访问者显示错误消息,而是为我创建日志

谢谢

可以试试

error_reporting(E_ERROR | E_PARSE);

确保php.ini中有类似的内容:

display_errors = Off
error_log = /var/log/php/error.log # Assuming you have /var/log/php directory and it's writable by httpd
error_reporting = E_ALL & ~E_DEPRECATED

或者使用
ini\u set()

将它们设置为运行时选项将其添加到脚本顶部:

//don't display errors
ini_set('display_errors', 0);
//write errors to log
ini_set('log_errors', 1);
//error log file name
ini_set('log_errors', '/var/log/php/error.log');

error_reporting(E_ALL);

如果要记录自定义错误:

try {
    // your code here
} catch (Exception $e){
    error_log($e->getMessage(), $e->getCode(), $e->getFile().' Line '.$e->getLine());
}
否则使用。

您需要这样做:使用ini设置(“显示错误”,“关闭”);方法将执行此操作。我使用
ini\u set()
,但仍然无法记录错误而不在浏览器上显示它。我也无法将错误记录到其他自定义文件