Skip to content

Commit 1a2c203

Browse files
come-ncmiaulalala
authored andcommitted
fix(logging): user log condition feature
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 41e0fcf commit 1a2c203

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

lib/private/Log.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@
3838

3939
use Exception;
4040
use Nextcloud\LogNormalizer\Normalizer;
41-
use OC\AppFramework\Bootstrap\Coordinator;
42-
use OCP\Log\IDataLogger;
43-
use Throwable;
44-
use function array_merge;
45-
use OC\Log\ExceptionSerializer;
41+
use OCP\EventDispatcher\IEventDispatcher;
4642
use OCP\ILogger;
43+
use OCP\IUserSession;
44+
use OCP\Log\BeforeMessageLoggedEvent;
45+
use OCP\Log\IDataLogger;
4746
use OCP\Log\IFileBased;
4847
use OCP\Log\IWriter;
4948
use OCP\Support\CrashReport\IRegistry;
49+
use OC\AppFramework\Bootstrap\Coordinator;
50+
use OC\Log\ExceptionSerializer;
51+
use Throwable;
52+
use function array_merge;
5053
use function strtr;
5154

5255
/**
@@ -247,7 +250,6 @@ public function getLogLevel($context) {
247250
// default to false to just process this once per request
248251
$this->logConditionSatisfied = false;
249252
if (!empty($logCondition)) {
250-
251253
// check for secret token in the request
252254
if (isset($logCondition['shared_secret'])) {
253255
$request = \OC::$server->getRequest();
@@ -268,10 +270,13 @@ public function getLogLevel($context) {
268270

269271
// check for user
270272
if (isset($logCondition['users'])) {
271-
$user = \OC::$server->getUserSession()->getUser();
273+
$user = \OCP\Server::get(IUserSession::class)->getUser();
272274

273-
// if the user matches set the log condition to satisfied
274-
if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
275+
if ($user === null) {
276+
// User is not known for this request yet
277+
$this->logConditionSatisfied = null;
278+
} elseif (in_array($user->getUID(), $logCondition['users'], true)) {
279+
// if the user matches set the log condition to satisfied
275280
$this->logConditionSatisfied = true;
276281
}
277282
}

0 commit comments

Comments
 (0)