diff --git a/lib/private/Log.php b/lib/private/Log.php index 2ad214ddec5e1..4ac7d3f2f880a 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -62,38 +62,26 @@ * MonoLog is an example implementing this interface. */ class Log implements ILogger, IDataLogger { - private ?SystemConfig $config; private ?bool $logConditionSatisfied = null; - private ?Normalizer $normalizer; - private ?IEventDispatcher $eventDispatcher; + private ?IEventDispatcher $eventDispatcher = null; - /** - * @param IWriter $logger The logger that should be used - * @param SystemConfig|null $config the system config object - * @param Normalizer|null $normalizer - * @param IRegistry|null $crashReporters - */ public function __construct( private IWriter $logger, - SystemConfig $config = null, - Normalizer $normalizer = null, - private ?IRegistry $crashReporters = null + private ?SystemConfig $config = null, + private ?Normalizer $normalizer = null, + private ?IRegistry $crashReporters = null ) { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if ($config === null) { - $config = \OC::$server->getSystemConfig(); + $this->config = \OCP\Server::get(SystemConfig::class); } - $this->config = $config; if ($normalizer === null) { $this->normalizer = new Normalizer(); - } else { - $this->normalizer = $normalizer; } - $this->eventDispatcher = null; } - public function setEventDispatcher(IEventDispatcher $eventDispatcher) { + public function setEventDispatcher(IEventDispatcher $eventDispatcher): void { $this->eventDispatcher = $eventDispatcher; } @@ -102,9 +90,8 @@ public function setEventDispatcher(IEventDispatcher $eventDispatcher) { * * @param string $message * @param array $context - * @return void */ - public function emergency(string $message, array $context = []) { + public function emergency(string $message, array $context = []): void { $this->log(ILogger::FATAL, $message, $context); } @@ -116,9 +103,8 @@ public function emergency(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function alert(string $message, array $context = []) { + public function alert(string $message, array $context = []): void { $this->log(ILogger::ERROR, $message, $context); } @@ -129,9 +115,8 @@ public function alert(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function critical(string $message, array $context = []) { + public function critical(string $message, array $context = []): void { $this->log(ILogger::ERROR, $message, $context); } @@ -141,9 +126,8 @@ public function critical(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function error(string $message, array $context = []) { + public function error(string $message, array $context = []): void { $this->log(ILogger::ERROR, $message, $context); } @@ -155,9 +139,8 @@ public function error(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function warning(string $message, array $context = []) { + public function warning(string $message, array $context = []): void { $this->log(ILogger::WARN, $message, $context); } @@ -166,9 +149,8 @@ public function warning(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function notice(string $message, array $context = []) { + public function notice(string $message, array $context = []): void { $this->log(ILogger::INFO, $message, $context); } @@ -179,9 +161,8 @@ public function notice(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function info(string $message, array $context = []) { + public function info(string $message, array $context = []): void { $this->log(ILogger::INFO, $message, $context); } @@ -190,9 +171,8 @@ public function info(string $message, array $context = []) { * * @param string $message * @param array $context - * @return void */ - public function debug(string $message, array $context = []) { + public function debug(string $message, array $context = []): void { $this->log(ILogger::DEBUG, $message, $context); } @@ -203,9 +183,8 @@ public function debug(string $message, array $context = []) { * @param int $level * @param string $message * @param array $context - * @return void */ - public function log(int $level, string $message, array $context = []) { + public function log(int $level, string $message, array $context = []): void { $minLevel = $this->getLogLevel($context); if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false) @@ -247,7 +226,7 @@ public function log(int $level, string $message, array $context = []) { } } - public function getLogLevel($context) { + public function getLogLevel($context): int { $logCondition = $this->config->getValue('log.condition', []); /** @@ -297,20 +276,16 @@ public function getLogLevel($context) { } if (isset($context['app'])) { - $app = $context['app']; - /** * check log condition based on the context of each log message * once this is met -> change the required log level to debug */ - if (!empty($logCondition) - && isset($logCondition['apps']) - && in_array($app, $logCondition['apps'], true)) { + if (in_array($context['app'], $logCondition['apps'] ?? [], true)) { return ILogger::DEBUG; } } - return min($this->config->getValue('loglevel', ILogger::WARN), ILogger::FATAL); + return min($this->config->getValue('loglevel', ILogger::WARN) ?? ILogger::WARN, ILogger::FATAL); } /** @@ -321,7 +296,7 @@ public function getLogLevel($context) { * @return void * @since 8.2.0 */ - public function logException(Throwable $exception, array $context = []) { + public function logException(Throwable $exception, array $context = []): void { $app = $context['app'] ?? 'no app in context'; $level = $context['level'] ?? ILogger::ERROR; @@ -395,7 +370,7 @@ public function logData(string $message, array $data, array $context = []): void * @param string|array $entry * @param int $level */ - protected function writeLog(string $app, $entry, int $level) { + protected function writeLog(string $app, $entry, int $level): void { $this->logger->write($app, $entry, $level); }