diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-01-03 19:03:57 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-01-16 09:47:31 +0100 |
commit | 00b7575c89815aa218e7e3ed3d61b25ee65f244f (patch) | |
tree | 002f0cc4ee86cb2c79eb8c8c089cbcba6c9511ac | |
parent | 5e090d044d3d660316450c3d4d2d7bfc3bde20dd (diff) | |
download | nextcloud-server-00b7575c89815aa218e7e3ed3d61b25ee65f244f.tar.gz nextcloud-server-00b7575c89815aa218e7e3ed3d61b25ee65f244f.zip |
perf(logging): Return early when log level does not match before serializing an exception
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | lib/private/Log.php | 6 | ||||
-rw-r--r-- | lib/private/Support/CrashReport/Registry.php | 4 | ||||
-rw-r--r-- | lib/public/Support/CrashReport/IRegistry.php | 9 |
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 4ab647bc6c1..e4be5134f11 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -312,6 +312,11 @@ class Log implements ILogger, IDataLogger { $app = $context['app'] ?? 'no app in context'; $level = $context['level'] ?? ILogger::ERROR; + $minLevel = $this->getLogLevel($context); + if ($level < $minLevel && ($this->crashReporters === null || !$this->crashReporters->hasReporters())) { + return; + } + // if an error is raised before the autoloader is properly setup, we can't serialize exceptions try { $serializer = $this->getSerializer(); @@ -325,7 +330,6 @@ class Log implements ILogger, IDataLogger { $data = array_merge($serializer->serializeException($exception), $data); $data = $this->interpolateMessage($data, $context['message'] ?? '--', 'CustomMessage'); - $minLevel = $this->getLogLevel($context); array_walk($context, [$this->normalizer, 'format']); diff --git a/lib/private/Support/CrashReport/Registry.php b/lib/private/Support/CrashReport/Registry.php index 472f39c2884..f5457f60ad4 100644 --- a/lib/private/Support/CrashReport/Registry.php +++ b/lib/private/Support/CrashReport/Registry.php @@ -147,4 +147,8 @@ class Registry implements IRegistry { } } } + + public function hasReporters(): bool { + return !empty($this->lazyReporters) || !empty($this->reporters); + } } diff --git a/lib/public/Support/CrashReport/IRegistry.php b/lib/public/Support/CrashReport/IRegistry.php index 6ee2b57f613..35cf78920da 100644 --- a/lib/public/Support/CrashReport/IRegistry.php +++ b/lib/public/Support/CrashReport/IRegistry.php @@ -81,4 +81,13 @@ interface IRegistry { * @since 17.0.0 */ public function delegateMessage(string $message, array $context = []): void; + + /** + * Check if any reporter has been registered to delegate to + * + * @return bool + * @deprecated use internally only + * @since 26.0.0 + */ + public function hasReporters(): bool; } |