logging: Fix that setting a numeric log level is flawed

This commit is contained in:
Eric Lippmann 2014-10-23 03:48:10 +02:00
parent f68c591a46
commit f44b0525d8

View File

@ -84,7 +84,8 @@ class Logger
if (($level = $config->level) !== null) { if (($level = $config->level) !== null) {
if (is_numeric($level)) { if (is_numeric($level)) {
if (! isset(static::$levels[(int) $level])) { $level = (int) $level;
if (! isset(static::$levels[$level])) {
throw new ConfigurationError( throw new ConfigurationError(
'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the' 'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the'
. ' Logger\'s constants.', . ' Logger\'s constants.',
@ -92,7 +93,7 @@ class Logger
implode(', ', array_keys(static::$levels)) implode(', ', array_keys(static::$levels))
); );
} }
$this->level = static::$levels[(int) $level]; $this->level = $level;
} else { } else {
$level = strtoupper($level); $level = strtoupper($level);
$levels = array_flip(static::$levels); $levels = array_flip(static::$levels);