diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-02-12 13:43:50 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-02-14 09:40:21 -0100 |
commit | 9a299ed60beca9318c30782a470ae97293b569e1 (patch) | |
tree | 4f1c9ddeffbd3d4b4e8c924496ef2be3d73f759b | |
parent | 3fb1674251569e4972554f6500a66986eedfebf3 (diff) | |
download | nextcloud-server-9a299ed60beca9318c30782a470ae97293b569e1.tar.gz nextcloud-server-9a299ed60beca9318c30782a470ae97293b569e1.zip |
exit log() early if no crashreporter registered
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/private/Log.php | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 9975696ff06..83ff1003294 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -62,24 +62,22 @@ use function strtr; * MonoLog is an example implementing this interface. */ class Log implements ILogger, IDataLogger { - private IWriter $logger; private ?SystemConfig $config; private ?bool $logConditionSatisfied = null; private ?Normalizer $normalizer; - private ?IRegistry $crashReporters; private ?IEventDispatcher $eventDispatcher; /** * @param IWriter $logger The logger that should be used - * @param SystemConfig $config the system config object + * @param SystemConfig|null $config the system config object * @param Normalizer|null $normalizer - * @param IRegistry|null $registry + * @param IRegistry|null $crashReporters */ public function __construct( - IWriter $logger, + private IWriter $logger, SystemConfig $config = null, Normalizer $normalizer = null, - IRegistry $registry = null + private ?IRegistry $crashReporters = null ) { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if ($config === null) { @@ -87,13 +85,11 @@ class Log implements ILogger, IDataLogger { } $this->config = $config; - $this->logger = $logger; if ($normalizer === null) { $this->normalizer = new Normalizer(); } else { $this->normalizer = $normalizer; } - $this->crashReporters = $registry; $this->eventDispatcher = null; } @@ -211,6 +207,9 @@ class Log implements ILogger, IDataLogger { */ public function log(int $level, string $message, array $context = []) { $minLevel = $this->getLogLevel($context); + if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) { + return; // we already know that log will be fully ignored + } array_walk($context, [$this->normalizer, 'format']); @@ -241,9 +240,7 @@ class Log implements ILogger, IDataLogger { $this->crashReporters->delegateMessage($entry['message'], $messageContext); } } else { - if ($this->crashReporters !== null) { - $this->crashReporters->delegateBreadcrumb($entry['message'], 'log', $context); - } + $this->crashReporters?->delegateBreadcrumb($entry['message'], 'log', $context); } } catch (Throwable $e) { // make sure we dont hard crash if logging fails @@ -329,8 +326,8 @@ class Log implements ILogger, IDataLogger { $level = $context['level'] ?? ILogger::ERROR; $minLevel = $this->getLogLevel($context); - if ($level < $minLevel && ($this->crashReporters === null || !$this->crashReporters->hasReporters())) { - return; + if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) { + return; // we already know that log will be fully ignored } // if an error is raised before the autoloader is properly setup, we can't serialize exceptions |