PHPUnit接收系统日志消息?
I am testing a logger class with a method that opens a log like so:
openlog($this->identifier, $this->option, $this->facility);
syslog($level, $message)
closelog();
The $facility
that my logger writes to is currently set as LOCAL0
When I unit test my logger I get the following message:
Broadcast message from systemd-journald@myWS:
phpserver7.0[9125]: Logger message
How can I suppress this message with PHPUnit or in my code?
Edit:
This only seems to happen when I log a message with a severity of "emergency" meaning a severity level of 0.
https://en.wikipedia.org/wiki/Syslog#Severity_level
Wikipedia states:
This level should not be used by applications.
Still, it is part of the PSR-3 logger abstract though so I would just like to be able to suppress the message with PHPUnit.
我正在使用打开日志的方法测试记录器类: p>
openlog($ this-> identifier,$ this-> option,$ this-> facility);
syslog($ level,$ message)
closelog();
code> pre>
我的记录器写入的 $ facility code>当前设置为 LOCAL0 code> p>
我对我的记录器进行单元测试我收到以下消息: p>
来自systemd-journald的广播消息@myWS:
nphpserver7.0 [9125]:记录消息
code> pre>
如何使用PHPUnit或我的代码抑制此消息? p>
编辑: p>
只有当我记录严重性为“紧急”的消息时才会出现这种情况,这意味着严重性级别为0. p>
https://en.wikipedia.org/wiki/Syslog#Severity_level p>
维基百科声明: p>
应用程序不应使用此级别。 p >
blockquote>
尽管如此,它仍然是PSR-3记录器摘要的一部分,所以我只想用PHPUnit来抑制消息。 p>
DIV>
In your test method, you can suppress output by wrapping an output buffer around your call that produces output. Example:
/**
* @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();
}