Merge branch '3.4' into 4.4
* 3.4: [PhpUnitBridge] fix bad detection of unsilenced deprecations [HttpKernel] Fix error logger when stderr is redirected to /dev/null (FPM)
This commit is contained in:
commit
fd584bb9b3
@ -113,7 +113,7 @@ class DeprecationErrorHandler
|
|||||||
$filesStack[] = $frame['file'];
|
$filesStack[] = $frame['file'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$deprecations[] = [error_reporting(), $msg, $file, $filesStack];
|
$deprecations[] = [error_reporting() & $type, $msg, $file, $filesStack];
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -143,7 +143,7 @@ class DeprecationErrorHandler
|
|||||||
$method = $deprecation->originatingMethod();
|
$method = $deprecation->originatingMethod();
|
||||||
$msg = $deprecation->getMessage();
|
$msg = $deprecation->getMessage();
|
||||||
|
|
||||||
if (0 !== error_reporting()) {
|
if (error_reporting() & $type) {
|
||||||
$group = 'unsilenced';
|
$group = 'unsilenced';
|
||||||
} elseif ($deprecation->isLegacy()) {
|
} elseif ($deprecation->isLegacy()) {
|
||||||
$group = 'legacy';
|
$group = 'legacy';
|
||||||
|
@ -310,7 +310,7 @@ class SymfonyTestsListenerTrait
|
|||||||
if (\is_array($parsedMsg)) {
|
if (\is_array($parsedMsg)) {
|
||||||
$msg = $parsedMsg['deprecation'];
|
$msg = $parsedMsg['deprecation'];
|
||||||
}
|
}
|
||||||
if (error_reporting()) {
|
if (error_reporting() & $type) {
|
||||||
$msg = 'Unsilenced deprecation: '.$msg;
|
$msg = 'Unsilenced deprecation: '.$msg;
|
||||||
}
|
}
|
||||||
$this->gatheredDeprecations[] = $msg;
|
$this->gatheredDeprecations[] = $msg;
|
||||||
|
@ -37,10 +37,10 @@ class Logger extends AbstractLogger
|
|||||||
private $formatter;
|
private $formatter;
|
||||||
private $handle;
|
private $handle;
|
||||||
|
|
||||||
public function __construct(string $minLevel = null, $output = 'php://stderr', callable $formatter = null)
|
public function __construct(string $minLevel = null, $output = null, callable $formatter = null)
|
||||||
{
|
{
|
||||||
if (null === $minLevel) {
|
if (null === $minLevel) {
|
||||||
$minLevel = 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::CRITICAL : LogLevel::WARNING;
|
$minLevel = null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING;
|
||||||
|
|
||||||
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
|
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
|
||||||
switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) {
|
switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) {
|
||||||
@ -58,7 +58,7 @@ class Logger extends AbstractLogger
|
|||||||
|
|
||||||
$this->minLevelIndex = self::$levels[$minLevel];
|
$this->minLevelIndex = self::$levels[$minLevel];
|
||||||
$this->formatter = $formatter ?: [$this, 'format'];
|
$this->formatter = $formatter ?: [$this, 'format'];
|
||||||
if (false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
|
if ($output && false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
|
||||||
throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
|
throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,10 +79,14 @@ class Logger extends AbstractLogger
|
|||||||
}
|
}
|
||||||
|
|
||||||
$formatter = $this->formatter;
|
$formatter = $this->formatter;
|
||||||
@fwrite($this->handle, $formatter($level, $message, $context));
|
if ($this->handle) {
|
||||||
|
@fwrite($this->handle, $formatter($level, $message, $context));
|
||||||
|
} else {
|
||||||
|
error_log($formatter($level, $message, $context, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function format(string $level, string $message, array $context): string
|
private function format(string $level, string $message, array $context, bool $prefixDate = true): string
|
||||||
{
|
{
|
||||||
if (false !== strpos($message, '{')) {
|
if (false !== strpos($message, '{')) {
|
||||||
$replacements = [];
|
$replacements = [];
|
||||||
@ -101,6 +105,11 @@ class Logger extends AbstractLogger
|
|||||||
$message = strtr($message, $replacements);
|
$message = strtr($message, $replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf('%s [%s] %s', date(\DateTime::RFC3339), $level, $message).PHP_EOL;
|
$log = sprintf('[%s] %s', $level, $message).PHP_EOL;
|
||||||
|
if ($prefixDate) {
|
||||||
|
$log = date(\DateTime::RFC3339).' '.$log;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $log;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user