Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,9 @@ public function getLogLevel(array $context, string $message): int {
}
}

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))
Expand All @@ -300,6 +289,14 @@ public function getLogLevel(array $context, string $message): int {
}
}

$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;
}
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ public function testMatchesCondition(string $userId, array $conditions, array $e
$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 */
Expand Down
Loading