Skip to content

Commit 9532d47

Browse files
committed
Make use of toMonologLevel for level conversion
1 parent 3916ec1 commit 9532d47

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

DependencyInjection/Configuration.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -998,17 +998,18 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
998998
$verbosity
999999
));
10001000
}
1001-
if (!is_numeric($level)) {
1002-
$levelConstant = 'Monolog\Logger::'.$level;
1003-
if (!defined($levelConstant)) {
1004-
throw new InvalidConfigurationException(sprintf(
1005-
'The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.',
1006-
$level, $verbosity
1007-
));
1001+
1002+
try {
1003+
if (Logger::API === 3) {
1004+
$level = Logger::toMonologLevel($level)->value;
1005+
} else {
1006+
$level = Logger::toMonologLevel(is_numeric($level) ? (int) $level : $level);
10081007
}
1009-
$level = constant($levelConstant);
1010-
} else {
1011-
$level = (int) $level;
1008+
} catch (\Psr\Log\InvalidArgumentException $e) {
1009+
throw new InvalidConfigurationException(sprintf(
1010+
'The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.',
1011+
$level, $verbosity
1012+
));
10121013
}
10131014

10141015
$map[constant($verbosityConstant)] = $level;

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function testWithConsoleHandler()
257257
'verbosity_levels' => [
258258
'VERBOSITY_NORMAL' => 'NOTICE',
259259
'verbosity_verbose' => 'info',
260-
'VERBOSITY_very_VERBOSE' => 150
260+
'VERBOSITY_very_VERBOSE' => '200'
261261
]
262262
]
263263
]
@@ -270,7 +270,7 @@ public function testWithConsoleHandler()
270270
$this->assertSame([
271271
OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE,
272272
OutputInterface::VERBOSITY_VERBOSE => Logger::INFO,
273-
OutputInterface::VERBOSITY_VERY_VERBOSE => 150,
273+
OutputInterface::VERBOSITY_VERY_VERBOSE => 200,
274274
OutputInterface::VERBOSITY_QUIET => Logger::ERROR,
275275
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG
276276
], $config['handlers']['console']['verbosity_levels']);

0 commit comments

Comments
 (0)