Skip to content

Commit 651d3c1

Browse files
committed
[HttpKernel] Fix error logger when stderr is redirected to /dev/null (FPM)
1 parent cb7e78c commit 651d3c1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Symfony/Component/HttpKernel/Log/Logger.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class Logger extends AbstractLogger
3737
private $formatter;
3838
private $handle;
3939

40-
public function __construct($minLevel = null, $output = 'php://stderr', callable $formatter = null)
40+
public function __construct($minLevel = null, $output = null, callable $formatter = null)
4141
{
4242
if (null === $minLevel) {
43-
$minLevel = 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::CRITICAL : LogLevel::WARNING;
43+
$minLevel = null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING;
4444

4545
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
4646
switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) {
@@ -58,7 +58,7 @@ public function __construct($minLevel = null, $output = 'php://stderr', callable
5858

5959
$this->minLevelIndex = self::$levels[$minLevel];
6060
$this->formatter = $formatter ?: [$this, 'format'];
61-
if (false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
61+
if ($output && false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
6262
throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
6363
}
6464
}
@@ -77,7 +77,11 @@ public function log($level, $message, array $context = [])
7777
}
7878

7979
$formatter = $this->formatter;
80-
@fwrite($this->handle, $formatter($level, $message, $context));
80+
if ($this->handle) {
81+
@fwrite($this->handle, $formatter($level, $message, $context));
82+
} else {
83+
error_log($formatter($level, $message, $context));
84+
}
8185
}
8286

8387
/**

0 commit comments

Comments
 (0)