Set the configured logging level even if the configured logging type is invalid
refs #8957
This commit is contained in:
parent
46296dce95
commit
67ad575cf5
|
@ -506,12 +506,21 @@ abstract class ApplicationBootstrap
|
|||
protected function setupLogger()
|
||||
{
|
||||
if ($this->config->hasSection('logging')) {
|
||||
$loggingConfig = $this->config->getSection('logging');
|
||||
|
||||
try {
|
||||
Logger::create($this->config->getSection('logging'));
|
||||
Logger::create($loggingConfig);
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error($e);
|
||||
|
||||
try {
|
||||
Logger::getInstance()->setLevel($loggingConfig->get('level', Logger::ERROR));
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,39 +81,53 @@ class Logger
|
|||
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
|
||||
}
|
||||
|
||||
if (($level = $config->level) !== null) {
|
||||
if (is_numeric($level)) {
|
||||
$level = (int) $level;
|
||||
if (! isset(static::$levels[$level])) {
|
||||
throw new ConfigurationError(
|
||||
'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the'
|
||||
. ' Logger\'s constants.',
|
||||
$level,
|
||||
implode(', ', array_keys(static::$levels))
|
||||
);
|
||||
}
|
||||
$this->level = $level;
|
||||
} else {
|
||||
$level = strtoupper($level);
|
||||
$levels = array_flip(static::$levels);
|
||||
if (! isset($levels[$level])) {
|
||||
throw new ConfigurationError(
|
||||
'Can\'t set logging level "%s". Logging level is not defined. Use one of %s.',
|
||||
$level,
|
||||
implode(', ', array_keys($levels))
|
||||
);
|
||||
}
|
||||
$this->level = $levels[$level];
|
||||
}
|
||||
} else {
|
||||
$this->level = static::ERROR;
|
||||
}
|
||||
$this->setLevel($config->get('level', static::ERROR));
|
||||
|
||||
if (strtolower($config->get('log', 'syslog')) !== 'none') {
|
||||
$this->writer = $this->createWriter($config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the logging level to use
|
||||
*
|
||||
* @param mixed $level
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws ConfigurationError In case the given level is invalid
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
if (is_numeric($level)) {
|
||||
$level = (int) $level;
|
||||
if (! isset(static::$levels[$level])) {
|
||||
throw new ConfigurationError(
|
||||
'Can\'t set logging level %d. Logging level is invalid. Use one of %s or one of the'
|
||||
. ' Logger\'s constants.',
|
||||
$level,
|
||||
implode(', ', array_keys(static::$levels))
|
||||
);
|
||||
}
|
||||
|
||||
$this->level = $level;
|
||||
} else {
|
||||
$level = strtoupper($level);
|
||||
$levels = array_flip(static::$levels);
|
||||
if (! isset($levels[$level])) {
|
||||
throw new ConfigurationError(
|
||||
'Can\'t set logging level "%s". Logging level is invalid. Use one of %s.',
|
||||
$level,
|
||||
implode(', ', array_keys($levels))
|
||||
);
|
||||
}
|
||||
|
||||
$this->level = $levels[$level];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new logger object
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue