From 008249440a9690d1f99862527447bba954ebcc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Thu, 26 Feb 2026 23:12:20 +0100 Subject: [PATCH] fix: Use configured loglevel even when log.condition matches is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- lib/private/Log.php | 23 ++++++++++------------- tests/lib/LoggerTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/lib/private/Log.php b/lib/private/Log.php index 301a25d12c1..9b7a075872e 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -268,20 +268,9 @@ 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); - } + $logConditionMatches = $logCondition['matches'] ?? []; - // 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; - } - - foreach ($logCondition['matches'] as $option) { + foreach ($logConditionMatches as $option) { if ( (!isset($option['shared_secret']) || $this->checkLogSecret($option['shared_secret'])) && (!isset($option['users']) || in_array($userId, $option['users'], true)) @@ -299,6 +288,14 @@ class Log implements ILogger, IDataLogger { } } + $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; } diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php index 7ad6638537f..97f5307cfdb 100644 --- a/tests/lib/LoggerTest.php +++ b/tests/lib/LoggerTest.php @@ -159,6 +159,34 @@ class LoggerTest extends TestCase implements IWriter { $this->assertEquals($expectedLogs, $this->getLogs()); } + public function testMatchesConditionIncreaseLoglevel(): void { + $this->config->expects($this->any()) + ->method('getValue') + ->willReturnMap([ + ['loglevel', ILogger::WARN, ILogger::INFO], + ['log.condition', [], ['matches' => [ + [ + 'message' => 'catched', + 'loglevel' => 3, + ] + ]]], + ]); + $logger = $this->logger; + + $user = $this->createMock(IUser::class); + $user->method('getUID') + ->willReturn('test-userid'); + $userSession = $this->createMock(IUserSession::class); + $userSession->method('getUser') + ->willReturn($user); + $this->overwriteService(IUserSession::class, $userSession); + + $logger->info('catched message'); + $logger->info('info level message'); + + $this->assertEquals(['1 info level message'], $this->getLogs()); + } + public function testLoggingWithDataArray(): void { $this->mockDefaultLogLevel(); /** @var IWriter&MockObject */