Skip to content

Commit 36f9ca2

Browse files
come-ncmiaulalala
authored andcommitted
fix(loggging): user log condition feature
Signed-off-by: Anna Larch <[email protected]>
1 parent c194698 commit 36f9ca2

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/private/Log.php

Lines changed: 18 additions & 9 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
/**
@@ -71,7 +72,12 @@ class Log implements ILogger, IDataLogger {
7172
* @param Normalizer|null $normalizer
7273
* @param IRegistry|null $registry
7374
*/
74-
public function __construct(IWriter $logger, SystemConfig $config = null, Normalizer $normalizer = null, IRegistry $registry = null) {
75+
public function __construct(
76+
IWriter $logger,
77+
SystemConfig $config = null,
78+
Normalizer $normalizer = null,
79+
IRegistry $registry = null
80+
) {
7581
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
7682
if ($config === null) {
7783
$config = \OC::$server->getSystemConfig();
@@ -257,10 +263,13 @@ public function getLogLevel($context) {
257263

258264
// check for user
259265
if (isset($logCondition['users'])) {
260-
$user = \OC::$server->getUserSession()->getUser();
266+
$user = \OCP\Server::get(IUserSession::class)->getUser();
261267

262-
// if the user matches set the log condition to satisfied
263-
if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
268+
if ($user === null) {
269+
// User is not known for this request yet
270+
$this->logConditionSatisfied = null;
271+
} elseif (in_array($user->getUID(), $logCondition['users'], true)) {
272+
// if the user matches set the log condition to satisfied
264273
$this->logConditionSatisfied = true;
265274
}
266275
}

0 commit comments

Comments
 (0)