From c28796ed746cc5d61114cbd41e3cc2601b4311a8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 8 Sep 2015 16:34:41 +0100 Subject: [PATCH] Use stderr by default when a specific output is not injected --- .../Bridge/Monolog/Handler/ConsoleHandler.php | 13 ++++----- .../Tests/Handler/ConsoleHandlerTest.php | 27 +------------------ 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php b/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php index a4c19cdb6af1d..592584ffa4af0 100644 --- a/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php @@ -120,7 +120,12 @@ public function close() */ 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 @@ public static function getSubscribedEvents() */ 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']); } /** diff --git a/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php b/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php index 65f259693ba3e..6cb315967e4fc 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php @@ -110,7 +110,7 @@ public function testGetFormatter() 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 @@ public function testWritingAndFormatting() ->with('[2013-05-29 16:21:54] app.INFO: My info message '."\n") ; - $errorOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $errorOutput - ->expects($this->once()) - ->method('write') - ->with('[2013-05-29 16:21:54] app.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 @@ public function testWritingAndFormatting() ); $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()