Skip to content

Commit eff9a26

Browse files
committed
bug #15728 Use stderr by default when a specific output is not injected (Seldaek)
This PR was merged into the 2.7 branch. Discussion ---------- Use stderr by default when a specific output is not injected | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | stderr is really the best place to put logs by default, so unless someone explicitly passes something else we should use it, and especially not depend on the log level to decide where to output. Commits ------- c28796e Use stderr by default when a specific output is not injected
2 parents 2f31cbf + c28796e commit eff9a26

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)