isLoggerLoaded() && !($this->logger instanceof NullLogger)) { $logger = new LoggerAggregator([$logger, $this->logger]); } $this->logger = $logger; return $logger; } /** * Get the logger * * @return LoggerInterface */ public function getLogger() { if (!$this->isLoggerLoaded()) { $this->loadLogger(); } return $this->logger; } /** * Wrap a log to built logger * * @param mixed $level * @param string $message * @param array $context */ public function log($level, $message, array $context = []) { $this->getLogger()->log($level, $message, $context); } /** * Load the logger from configuration * * If options does not contain any Psr3 Logger, NullLogger is set by default * * @return LoggerInterface */ protected function loadLogger() { $logger = null; if ($this->hasOption(self::LOGGER_OPTION)) { $loggerOptions = $this->getOption(self::LOGGER_OPTION); if (is_object($loggerOptions)) { if (is_a($loggerOptions, LoggerInterface::class)) { $logger = $loggerOptions; } } elseif (is_array($loggerOptions) && isset($loggerOptions['class'])) { $classname = $loggerOptions['class']; if (is_a($classname, LoggerInterface::class, true)) { if (isset($loggerOptions['options'])) { $logger = new $classname($loggerOptions['options']); } else { $logger = new $classname(); } } } } if (!is_null($logger)) { $this->logger = $logger; } else { $this->logger = new NullLogger(); } return $this->logger; } /** * Check if the logger is loaded from configuration * * @return bool */ protected function isLoggerLoaded() { return $this->logger instanceof LoggerInterface; } }