PHP 错误配置对 error_log 功能的影响

PHP effect of error configurations on error_log function

我的 Laravel 项目中有一组 PHP 单元测试,当我 运行 在终端中进行测试时,我试图不显示错误。我在每个异常上使用 error_log() 函数手动记录错误。我已尝试将 php.ini 错误参数设置为不显示错误,但似乎不起作用。

ini_set('log_errors', 0);
ini_set('error_reporting', 0);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);

error_log("This is an exception");

即使在上述设置之后,我也在控制台中得到了字符串 This is an exception。我在这里做错了什么吗? PHP 版本为 7。提前致谢。

error_log ini 指令控制 error_log() 函数输出的位置。当未设置该指令时,CLI 将输出到 stderr。此外,如果由于某种原因您无法设置指令,您可以将额外的参数传递给 error_log() 函数来控制输出目标。

因此,例如,如果您希望将错误写出到 /var/log/php.log,您有两个选择:

ini 指令:

ini_set('error_log', '/var/log/php.log');

error_log('destination set by error_log directive');

error_log参数:

error_log(
    'destination set by parameters'.PHP_EOL, // this method doesn't auto append EOL; must add it manually
    3, // destination type; 3 = file
    '/var/log/php.log' // destination file
);

您可以在文档中阅读更多内容:
error_log() 函数
error_log ini 指令