mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
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()
|
protected function setupLogger()
|
||||||
{
|
{
|
||||||
if ($this->config->hasSection('logging')) {
|
if ($this->config->hasSection('logging')) {
|
||||||
|
$loggingConfig = $this->config->getSection('logging');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Logger::create($this->config->getSection('logging'));
|
Logger::create($loggingConfig);
|
||||||
} catch (ConfigurationError $e) {
|
} catch (ConfigurationError $e) {
|
||||||
Logger::error($e);
|
Logger::error($e);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Logger::getInstance()->setLevel($loggingConfig->get('level', Logger::ERROR));
|
||||||
|
} catch (ConfigurationError $e) {
|
||||||
|
Logger::error($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,39 +81,53 @@ class Logger
|
|||||||
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
|
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($level = $config->level) !== null) {
|
$this->setLevel($config->get('level', static::ERROR));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strtolower($config->get('log', 'syslog')) !== 'none') {
|
if (strtolower($config->get('log', 'syslog')) !== 'none') {
|
||||||
$this->writer = $this->createWriter($config);
|
$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
|
* Create a new logger object
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user