I am printing some lines on via the ConsoleOuput
. I like to use the Table Helper, yet it uses StdOut by default and this seems to be hardcoded, as in the \Symfony/Component/Console/Output/ConsoleOutput.php
, it says:
* This class is a convenient wrapper around `StreamOutput`.
*
* $output = new ConsoleOutput();
*
* This is equivalent to:
*
* $output = new StreamOutput(fopen('php://stdout', 'w'));
Within the project we have Log4Php, and are storing it to a file by changing the default output from stdout to a customized output.
Is there a way to change the output of the ConsoleOutput to something else than sdtout?
Because as of now, I can see the output in the command line in StdOut, yet when the php4log output is redirected to a file, the ConsoleOutput will still be in StdOut.
How can I merge those output together?
Use BufferedOutput()
instead of the ConsoleOutput()
. It will store the message and you then can use the messages whereever you want them to.
Use the $output->fetch()
method to get the message as a string. The string contain of all write operations you did on the OutputInterface
before and the method call will also empty the buffer.
If you need to use it in a different logger, in your case a log4php instance, it would look something like:
$this->getLog4PhpLogger()
->info(
$this->output->fetch()
);