Use stderr by default when a specific output is not injected

This commit is contained in:
Jordi Boggiano 2015-09-08 16:34:41 +01:00
parent 1fdf23fe28
commit c28796ed74
2 changed files with 8 additions and 32 deletions

View File

@ -120,7 +120,12 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
*/
public function onCommand(ConsoleCommandEvent $event)
{
$this->setOutput($event->getOutput());
$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
$this->setOutput($output);
}
/**
@ -149,11 +154,7 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
*/
protected function write(array $record)
{
if ($record['level'] >= Logger::ERROR && $this->output instanceof ConsoleOutputInterface) {
$this->output->getErrorOutput()->write((string) $record['formatted']);
} else {
$this->output->write((string) $record['formatted']);
}
$this->output->write((string) $record['formatted']);
}
/**

View File

@ -110,7 +110,7 @@ class ConsoleHandlerTest extends \PHPUnit_Framework_TestCase
public function testWritingAndFormatting()
{
$output = $this->getMock('Symfony\Component\Console\Output\ConsoleOutputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output
->expects($this->any())
->method('getVerbosity')
@ -122,19 +122,6 @@ class ConsoleHandlerTest extends \PHPUnit_Framework_TestCase
->with('<info>[2013-05-29 16:21:54] app.INFO:</info> My info message '."\n")
;
$errorOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$errorOutput
->expects($this->once())
->method('write')
->with('<error>[2013-05-29 16:21:54] app.ERROR:</error> My error message '."\n")
;
$output
->expects($this->any())
->method('getErrorOutput')
->will($this->returnValue($errorOutput))
;
$handler = new ConsoleHandler(null, false);
$handler->setOutput($output);
@ -149,18 +136,6 @@ class ConsoleHandlerTest extends \PHPUnit_Framework_TestCase
);
$this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
$errorRecord = array(
'message' => 'My error message',
'context' => array(),
'level' => Logger::ERROR,
'level_name' => Logger::getLevelName(Logger::ERROR),
'channel' => 'app',
'datetime' => new \DateTime('2013-05-29 16:21:54'),
'extra' => array(),
);
$this->assertTrue($handler->handle($errorRecord), 'The handler finished handling the log as bubble is false.');
}
public function testLogsFromListeners()