Skip to content

Commit c28796e

Browse files
committed
Use stderr by default when a specific output is not injected
1 parent 1fdf23f commit c28796e

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ public function close()
120120
*/
121121
public function onCommand(ConsoleCommandEvent $event)
122122
{
123-
$this->setOutput($event->getOutput());
123+
$output = $event->getOutput();
124+
if ($output instanceof ConsoleOutputInterface) {
125+
$output = $output->getErrorOutput();
126+
}
127+
128+
$this->setOutput($output);
124129
}
125130

126131
/**
@@ -149,11 +154,7 @@ public static function getSubscribedEvents()
149154
*/
150155
protected function write(array $record)
151156
{
152-
if ($record['level'] >= Logger::ERROR && $this->output instanceof ConsoleOutputInterface) {
153-
$this->output->getErrorOutput()->write((string) $record['formatted']);
154-
} else {
155-
$this->output->write((string) $record['formatted']);
156-
}
157+
$this->output->write((string) $record['formatted']);
157158
}
158159

159160
/**

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testGetFormatter()
110110

111111
public function testWritingAndFormatting()
112112
{
113-
$output = $this->getMock('Symfony\Component\Console\Output\ConsoleOutputInterface');
113+
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
114114
$output
115115
->expects($this->any())
116116
->method('getVerbosity')
@@ -122,19 +122,6 @@ public function testWritingAndFormatting()
122122
->with('<info>[2013-05-29 16:21:54] app.INFO:</info> My info message '."\n")
123123
;
124124

125-
$errorOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
126-
$errorOutput
127-
->expects($this->once())
128-
->method('write')
129-
->with('<error>[2013-05-29 16:21:54] app.ERROR:</error> My error message '."\n")
130-
;
131-
132-
$output
133-
->expects($this->any())
134-
->method('getErrorOutput')
135-
->will($this->returnValue($errorOutput))
136-
;
137-
138125
$handler = new ConsoleHandler(null, false);
139126
$handler->setOutput($output);
140127

@@ -149,18 +136,6 @@ public function testWritingAndFormatting()
149136
);
150137

151138
$this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
152-
153-
$errorRecord = array(
154-
'message' => 'My error message',
155-
'context' => array(),
156-
'level' => Logger::ERROR,
157-
'level_name' => Logger::getLevelName(Logger::ERROR),
158-
'channel' => 'app',
159-
'datetime' => new \DateTime('2013-05-29 16:21:54'),
160-
'extra' => array(),
161-
);
162-
163-
$this->assertTrue($handler->handle($errorRecord), 'The handler finished handling the log as bubble is false.');
164139
}
165140

166141
public function testLogsFromListeners()

0 commit comments

Comments
 (0)