我正通过ConsoleOuput
打印一些行。我喜欢使用Table Helper,但它默认使用StdOut,这似乎是硬编码的,就像在\Symfony/Component/Console/Output/ConsoleOutput.php
中一样,它说:
* This class is a convenient wrapper around `StreamOutput`.
*
* $output = new ConsoleOutput();
*
* This is equivalent to:
*
* $output = new StreamOutput(fopen('php://stdout', 'w'));
在项目中我们有Log4Php,并通过将默认输出从stdout更改为自定义输出来将其存储到文件中。
有没有办法将ConsoleOutput的输出更改为sdtout以外的其他内容?
因为到目前为止,我可以在StdOut的命令行中看到输出,但是当php4log输出被重定向到文件时,ConsoleOutput仍将在StdOut中。
如何将这些输出合并在一起?
答案 0 :(得分:1)
使用BufferedOutput()
代替ConsoleOutput()
。它将存储消息,然后您可以根据需要使用消息。
使用$output->fetch()
方法将消息作为字符串获取。该字符串包含您之前在OutputInterface
上执行的所有写操作,方法调用也将清空缓冲区。
如果您需要在不同的记录器中使用它,在您的情况下是log4php实例,它看起来像:
$this->getLog4PhpLogger()
->info(
$this->output->fetch()
);