我正在使用打开日志的方法测试记录器类,如下所示:
openlog($this->identifier, $this->option, $this->facility);
syslog($level, $message)
closelog();
The $facility
我的记录器写入当前设置为LOCAL0
当我对记录器进行单元测试时,我收到以下消息:
Broadcast message from systemd-journald@myWS:
phpserver7.0[9125]: Logger message
如何使用 PHPUnit 或在我的代码中抑制此消息?
Edit:
这种情况似乎仅在我记录严重性为“紧急”(即严重性级别为 0)的消息时才会发生。
https://en.wikipedia.org/wiki/Syslog#Severity_level https://en.wikipedia.org/wiki/Syslog#Severity_level
维基百科指出:
应用程序不应使用此级别。
尽管如此,它仍然是 PSR-3 记录器抽象的一部分,所以我只是希望能够使用 PHPUnit 抑制该消息。
在您的测试方法中,您可以通过将输出缓冲区包装在产生输出的调用周围来抑制输出。例子:
/**
* @preserveGlobalState disabled
* @runInSeparateProcess
*/
public function testOutputCanSend()
{
ob_start();
// Do some stuff here that outputs directly, e.g
openlog($this->identifier, $this->option, $this->facility);
syslog($level, $message)
closelog();
ob_end_clean();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)