Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public function close()
*/
public function onCommand(ConsoleCommandEvent $event)
{
$this->setOutput($event->getOutput());
$output = $event->getOutput();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For convenience, you could use a temporary variable:

$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
    $output = $output->getErrorOutput();
}

$this->setOutput($output);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's a bit nicer yes, fixed.

if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}

$this->setOutput($output);
}

/**
Expand Down Expand Up @@ -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']);
}

/**
Expand Down
27 changes: 1 addition & 26 deletions src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -122,19 +122,6 @@ public function testWritingAndFormatting()
->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);

Expand All @@ -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()
Expand Down