Do not log that the logging configuration is invalid on every request

Instead, log those messages *everytime* a subsequent message is being
logged.

refs #8957
This commit is contained in:
Johannes Meyer 2015-04-13 17:11:42 +02:00
parent 67ad575cf5
commit 36fed03764
2 changed files with 31 additions and 2 deletions

View File

@ -511,12 +511,12 @@ abstract class ApplicationBootstrap
try {
Logger::create($loggingConfig);
} catch (ConfigurationError $e) {
Logger::error($e);
Logger::getInstance()->registerConfigError($e->getMessage());
try {
Logger::getInstance()->setLevel($loggingConfig->get('level', Logger::ERROR));
} catch (ConfigurationError $e) {
Logger::error($e);
Logger::getInstance()->registerConfigError($e->getMessage());
}
}
}

View File

@ -67,6 +67,13 @@ class Logger
*/
protected $level;
/**
* Error messages to be displayed prior to any other log message
*
* @var array
*/
protected $configErrors = array();
/**
* Create a new logger object
*
@ -128,6 +135,24 @@ class Logger
return $this;
}
/**
* Register the given message as config error
*
* Config errors are logged every time a log message is being logged.
*
* @param mixed $arg,... A string, exception or format-string + substitutions
*
* @return $this
*/
public function registerConfigError()
{
if (func_num_args() > 0) {
$this->configErrors[] = static::formatMessage(func_get_args());
}
return $this;
}
/**
* Create a new logger object
*
@ -170,6 +195,10 @@ class Logger
public function log($level, $message)
{
if ($this->writer !== null && $this->level <= $level) {
foreach ($this->configErrors as $error_message) {
$this->writer->log(static::ERROR, $error_message);
}
$this->writer->log($level, $message);
}
}