Skip to content

Commit 66c6bc0

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

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/private/Log.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
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;
4641
use OCP\ILogger;
42+
use OCP\IUserSession;
43+
use OCP\Log\IDataLogger;
4744
use OCP\Log\IFileBased;
4845
use OCP\Log\IWriter;
4946
use OCP\Support\CrashReport\IRegistry;
47+
use OC\AppFramework\Bootstrap\Coordinator;
48+
use OC\Log\ExceptionSerializer;
49+
use Throwable;
50+
use function array_merge;
5051
use function strtr;
5152

5253
/**
@@ -59,7 +60,6 @@
5960
* MonoLog is an example implementing this interface.
6061
*/
6162
class Log implements ILogger, IDataLogger {
62-
6363
/** @var IWriter */
6464
private $logger;
6565

@@ -247,7 +247,6 @@ public function getLogLevel($context) {
247247
// default to false to just process this once per request
248248
$this->logConditionSatisfied = false;
249249
if (!empty($logCondition)) {
250-
251250
// check for secret token in the request
252251
if (isset($logCondition['shared_secret'])) {
253252
$request = \OC::$server->getRequest();
@@ -268,10 +267,13 @@ public function getLogLevel($context) {
268267

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

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

0 commit comments

Comments
 (0)