Explorar el Código

set username if not set

CauseFX hace 4 años
padre
commit
720e31d658
Se han modificado 2 ficheros con 7 adiciones y 4 borrados
  1. 1 1
      api/classes/organizr.class.php
  2. 6 3
      api/functions/log-functions.php

+ 1 - 1
api/classes/organizr.class.php

@@ -209,7 +209,7 @@ class Organizr
 			}
 		}
 		$this->user = ($user) ?: $this->guestUser();
-		$this->setLoggerChannel();
+		$this->setLoggerChannel(null, $this->user['username']);
 		if ($validate) {
 			$this->checkUserTokenForValidation();
 		}

+ 6 - 3
api/functions/log-functions.php

@@ -142,8 +142,10 @@ trait LogFunctions
 	{
 		$setLogger = false;
 		if ($this->logger) {
-			if (strtolower($this->logger->getChannel()) !== strtolower($channel)) {
-				$setLogger = true;
+			if ($channel) {
+				if (strtolower($this->logger->getChannel()) !== strtolower($channel)) {
+					$setLogger = true;
+				}
 			}
 			if ($username) {
 				if (strtolower($this->logger->getTraceId()) !== strtolower($channel)) {
@@ -154,6 +156,7 @@ trait LogFunctions
 			$setLogger = true;
 		}
 		if ($setLogger) {
+			$channel = $channel ?: 'Organizr';
 			$this->setupLogger($channel, $username);
 		}
 		return $this->logger;
@@ -163,7 +166,7 @@ trait LogFunctions
 	{
 		if ($this->log) {
 			if (!$username) {
-				$username = (isset($this->user['username'])) ? $this->user['username'] : 'System';
+				$username = $this->user['username'] ?? 'System';
 			}
 			$loggerBuilder = new Nekonomokochan\PhpJsonLogger\LoggerBuilder();
 			$loggerBuilder->setMaxFiles($this->config['maxLogFiles']);