diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-11-28 03:44:36 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-11-28 03:44:36 +0300 |
commit | 08ec3624a15e597fef3a4414f75b3482a160cea1 (patch) | |
tree | 26356fb56eb7b2be27eb3d592f924e77562baffa /core | |
parent | 95a7aa7427563d77381ceb0d78d5d034ff181637 (diff) |
#6622 Logger refactoring: use the container to get the log level
Diffstat (limited to 'core')
-rw-r--r-- | core/Log.php | 8 | ||||
-rw-r--r-- | core/Log/LoggerFactory.php | 21 |
2 files changed, 19 insertions, 10 deletions
diff --git a/core/Log.php b/core/Log.php index 4a047965c9..f9c628c1a5 100644 --- a/core/Log.php +++ b/core/Log.php @@ -184,10 +184,16 @@ class Log extends Singleton self::$instance = $instance; } - public function __construct($logMessageFormat, $logToFilePath) + /** + * @param string $logMessageFormat + * @param string $logToFilePath + * @param int $logLevel + */ + public function __construct($logMessageFormat, $logToFilePath, $logLevel) { $this->logMessageFormat = $logMessageFormat; $this->logToFilePath = $logToFilePath; + $this->currentLogLevel = $logLevel; } /** diff --git a/core/Log/LoggerFactory.php b/core/Log/LoggerFactory.php index 200b16f34d..6789927b14 100644 --- a/core/Log/LoggerFactory.php +++ b/core/Log/LoggerFactory.php @@ -24,27 +24,30 @@ class LoggerFactory $logConfig = Config::getInstance()->log; $logFilePath = self::getLogFilePath($logConfig, $container); + $logLevel = self::getLogLevel($container); - $logger = new Log($container->get('log.format'), $logFilePath); + $logger = new Log($container->get('log.format'), $logFilePath, $logLevel); - self::setCurrentLogLevelFromConfig($logger, $logConfig); self::setLogWritersFromConfig($logger, $logConfig); self::disableLoggingBasedOnConfig($logger, $logConfig); return $logger; } - private static function setCurrentLogLevelFromConfig(Log $logger, $logConfig) + private static function getLogLevel(ContainerInterface $container) { - if (!empty($logConfig[Log::LOG_LEVEL_CONFIG_OPTION])) { - $logLevel = self::getLogLevelFromStringName($logConfig[Log::LOG_LEVEL_CONFIG_OPTION]); + $logLevel = Log::WARN; - if ($logLevel >= Log::NONE // sanity check - && $logLevel <= Log::VERBOSE - ) { - $logger->setLogLevel($logLevel); + if ($container->has('old_config.log.log_level')) { + $configLogLevel = self::getLogLevelFromStringName($container->get('old_config.log.log_level')); + + // sanity check + if ($configLogLevel >= Log::NONE && $configLogLevel <= Log::VERBOSE) { + $logLevel = $configLogLevel; } } + + return $logLevel; } private static function setLogWritersFromConfig(Log $logger, $logConfig) |