summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-01-16 14:00:57 +0100
committerGitHub <noreply@github.com>2023-01-16 14:00:57 +0100
commit8557c61389e297130ee80828b680cbbd3485c697 (patch)
tree16f65997afbac0ff111b317f51d6ae4e52bdf79c /lib
parent052f09633b84cfb80e39b281e60c6dbffc3d3c36 (diff)
parentcf1bd0eb70e81915ba018afc22d3a2374b179cbe (diff)
downloadnextcloud-server-8557c61389e297130ee80828b680cbbd3485c697.tar.gz
nextcloud-server-8557c61389e297130ee80828b680cbbd3485c697.zip
Merge pull request #35970 from nextcloud/perf/noid/exception-serializer
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Log.php28
-rw-r--r--lib/private/Log/ExceptionSerializer.php6
-rw-r--r--lib/private/Support/CrashReport/Registry.php4
-rw-r--r--lib/public/Support/CrashReport/IRegistry.php9
4 files changed, 27 insertions, 20 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php
index 4ab647bc6c1..2ee5bfc9c5a 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -59,21 +59,11 @@ use function strtr;
* MonoLog is an example implementing this interface.
*/
class Log implements ILogger, IDataLogger {
-
- /** @var IWriter */
- private $logger;
-
- /** @var SystemConfig */
- private $config;
-
- /** @var boolean|null cache the result of the log condition check for the request */
- private $logConditionSatisfied = null;
-
- /** @var Normalizer */
- private $normalizer;
-
- /** @var IRegistry */
- private $crashReporters;
+ private IWriter $logger;
+ private ?SystemConfig $config;
+ private ?bool $logConditionSatisfied = null;
+ private ?Normalizer $normalizer;
+ private ?IRegistry $crashReporters;
/**
* @param IWriter $logger The logger that should be used
@@ -81,7 +71,7 @@ class Log implements ILogger, IDataLogger {
* @param Normalizer|null $normalizer
* @param IRegistry|null $registry
*/
- public function __construct(IWriter $logger, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) {
+ public function __construct(IWriter $logger, SystemConfig $config = null, Normalizer $normalizer = null, IRegistry $registry = null) {
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
if ($config === null) {
$config = \OC::$server->getSystemConfig();
@@ -312,6 +302,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 +320,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/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php
index aaf6a39235e..5f806be0ae5 100644
--- a/lib/private/Log/ExceptionSerializer.php
+++ b/lib/private/Log/ExceptionSerializer.php
@@ -223,13 +223,13 @@ class ExceptionSerializer {
}
private function encodeTrace($trace) {
- $filteredTrace = $this->filterTrace($trace);
- return array_map(function (array $line) {
+ $trace = array_map(function (array $line) {
if (isset($line['args'])) {
$line['args'] = array_map([$this, 'encodeArg'], $line['args']);
}
return $line;
- }, $filteredTrace);
+ }, $trace);
+ return $this->filterTrace($trace);
}
private function encodeArg($arg, $nestingLevel = 5) {
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;
}