mirror of
https://github.com/nextcloud/server.git
synced 2026-02-27 18:37:17 +01:00
Merge pull request #58613 from nextcloud/backport/58601/stable32
[stable32] fix: Use configured loglevel even when log.condition matches is set
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user