Skip to content

Commit a5b28e1

Browse files
committed
bug #373 Fix infinite loop in LogLevel detection (jderusse)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix infinite loop in LogLevel detection While converting the logLevel into the right const value, calling `$container->resolveEnvPlaceholders($level, true);` does not always throw an exception and returns the value provided in INPUT, leading to an infinite loop This PR fixes #367 (comment) BUT is not related to the issue #367 (comment) Commits ------- a36cd53 Fix infinite loop in LogLevel detection
2 parents ea72151 + a36cd53 commit a5b28e1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function levelToMonologConst($level, ContainerBuilder $container)
6262
throw new \InvalidArgumentException(sprintf('Could not match "%s" to a log level.', $level));
6363
}
6464

65-
if ($logLevel !== '') {
65+
if ($logLevel !== '' && $logLevel !== $level) {
6666
return $this->levelToMonologConst($logLevel, $container);
6767
}
6868

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public function testLoadWithCustomValues()
6060
$this->assertDICConstructorArguments($handler, ['/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666, true]);
6161
}
6262

63+
public function testLoadWithUnknownLevel()
64+
{
65+
$this->expectException(InvalidArgumentException::class);
66+
$this->expectExceptionMessage('Could not match "warn" to a log level.');
67+
$container = $this->getContainer([['handlers' => [
68+
'custom' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'warn', 'file_permission' => '0666', 'use_locking' => true]
69+
]]]);
70+
}
71+
6372
public function testLoadWithNestedHandler()
6473
{
6574
$container = $this->getContainer([['handlers' => [

0 commit comments

Comments
 (0)