diff options
Diffstat (limited to 'lib/private/Log.php')
-rw-r--r-- | lib/private/Log.php | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 98de9bfa858..301a25d12c1 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -37,6 +37,7 @@ use function strtr; class Log implements ILogger, IDataLogger { private ?bool $logConditionSatisfied = null; private ?IEventDispatcher $eventDispatcher = null; + private int $nestingLevel = 0; public function __construct( private IWriter $logger, @@ -192,6 +193,11 @@ class Log implements ILogger, IDataLogger { } public function getLogLevel(array $context, string $message): int { + if ($this->nestingLevel > 1) { + return ILogger::WARN; + } + + $this->nestingLevel++; /** * @psalm-var array{ * shared_secret?: string, @@ -242,6 +248,7 @@ class Log implements ILogger, IDataLogger { // if log condition is satisfied change the required log level to DEBUG if ($this->logConditionSatisfied) { + $this->nestingLevel--; return ILogger::DEBUG; } @@ -256,6 +263,7 @@ class Log implements ILogger, IDataLogger { * once this is met -> change the required log level to debug */ if (in_array($context['app'], $logCondition['apps'] ?? [], true)) { + $this->nestingLevel--; return ILogger::DEBUG; } } @@ -263,11 +271,13 @@ class Log implements ILogger, IDataLogger { if (!isset($logCondition['matches'])) { $configLogLevel = $this->config->getValue('loglevel', ILogger::WARN); if (is_numeric($configLogLevel)) { + $this->nestingLevel--; return min((int)$configLogLevel, ILogger::FATAL); } // Invalid configuration, warn the user and fall back to default level of WARN error_log('Nextcloud configuration: "loglevel" is not a valid integer'); + $this->nestingLevel--; return ILogger::WARN; } @@ -281,21 +291,24 @@ class Log implements ILogger, IDataLogger { if (!isset($option['apps']) && !isset($option['loglevel']) && !isset($option['message'])) { /* Only user and/or secret are listed as conditions, we can cache the result for the rest of the request */ $this->logConditionSatisfied = true; + $this->nestingLevel--; return ILogger::DEBUG; } + $this->nestingLevel--; return $option['loglevel'] ?? ILogger::DEBUG; } } + $this->nestingLevel--; return ILogger::WARN; } protected function checkLogSecret(string $conditionSecret): bool { $request = \OCP\Server::get(IRequest::class); - if ($request->getMethod() === 'PUT' && - !str_contains($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') && - !str_contains($request->getHeader('Content-Type'), 'application/json')) { + if ($request->getMethod() === 'PUT' + && !str_contains($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') + && !str_contains($request->getHeader('Content-Type'), 'application/json')) { return hash_equals($conditionSecret, ''); } |