Kaynağa Gözat

added correct field for username in logs bringing back trace_id [PLEASE DELETE ALL OLD LOGS]

CauseFX 4 yıl önce
ebeveyn
işleme
caf785afe1

+ 3 - 2
api/classes/logger.class.php

@@ -1,5 +1,6 @@
 <?php
 
+use Nekonomokochan\PhpJsonLogger\Logger;
 use Nekonomokochan\PhpJsonLogger\LoggerBuilder;
 
 class OrganizrLogger extends LoggerBuilder
@@ -22,13 +23,13 @@ class OrganizrLogger extends LoggerBuilder
 		$this->isReady = $readyStatus;
 	}
 	
-	public function build(): OrganizrLoggerExt
+	public function build(): Logger
 	{
 		if (!$this->isReady) {
 			$this->setChannel('Organizr');
 			$this->setLogLevel(self::DEBUG);
 			$this->setMaxFiles(1);
 		}
-		return new OrganizrLoggerExt($this);
+		return new Logger($this);
 	}
 }

+ 3 - 139
api/classes/loggerExt.class.php

@@ -1,140 +1,4 @@
 <?php
-
-use Nekonomokochan\PhpJsonLogger\Logger;
-
-class OrganizrLoggerExt extends Logger
-{
-	/**
-	 * @param $message
-	 * @param $context
-	 */
-	public function debug($message, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		$this->addDebug($message, $context);
-	}
-	
-	/**
-	 * @param $message
-	 * @param $context
-	 */
-	public function info($message, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		$this->addInfo($message, $context);
-	}
-	
-	/**
-	 * @param $message
-	 * @param $context
-	 */
-	public function notice($message, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		$this->addNotice($message, $context);
-	}
-	
-	/**
-	 * @param $message
-	 * @param $context
-	 */
-	public function warning($message, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		$this->addWarning($message, $context);
-	}
-	
-	/**
-	 * @param \Throwable $e
-	 * @param            $context
-	 */
-	public function error($e, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		if ($this->isErrorObject($e) === false) {
-			throw new \InvalidArgumentException(
-				$this->generateInvalidArgumentMessage(__METHOD__)
-			);
-		}
-		$this->addError(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
-	}
-	
-	/**
-	 * @param \Throwable $e
-	 * @param            $context
-	 */
-	public function critical($e, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		if ($this->isErrorObject($e) === false) {
-			throw new \InvalidArgumentException(
-				$this->generateInvalidArgumentMessage(__METHOD__)
-			);
-		}
-		$this->addCritical(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
-	}
-	
-	/**
-	 * @param \Throwable $e
-	 * @param            $context
-	 */
-	public function alert($e, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		if ($this->isErrorObject($e) === false) {
-			throw new \InvalidArgumentException(
-				$this->generateInvalidArgumentMessage(__METHOD__)
-			);
-		}
-		$this->addAlert(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
-	}
-	
-	/**
-	 * @param \Throwable $e
-	 * @param            $context
-	 */
-	public function emergency($e, $context = '')
-	{
-		$context = $this->formatParamToArray($context);
-		if ($this->isErrorObject($e) === false) {
-			throw new \InvalidArgumentException(
-				$this->generateInvalidArgumentMessage(__METHOD__)
-			);
-		}
-		$this->addEmergency(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
-	}
-	
-	/**
-	 * @param $value
-	 * @return bool
-	 */
-	private function isErrorObject($value): bool
-	{
-		if ($value instanceof \Exception || $value instanceof \Error) {
-			return true;
-		}
-		return false;
-	}
-	
-	/**
-	 * @param $value
-	 * @return array
-	 */
-	private function formatParamToArray($value): array
-	{
-		if (is_array($value)) {
-			return $value;
-		} else {
-			return (empty($value)) ? [] : ['context' => $value];
-		}
-	}
-	
-	/**
-	 * @param string $method
-	 * @return string
-	 */
-	private function generateInvalidArgumentMessage(string $method): string
-	{
-		return 'Please give the exception class to the ' . $method;
-	}
-}
+/*
+ * deprecated
+ */

+ 1 - 1
api/pages/settings-settings-logs.php

@@ -85,7 +85,7 @@ function get_page_settings_settings_logs($Organizr)
 				return ipInfoSpan(data);
 			}
 		}, {
-			"data": "trace_id"
+			"data": "username"
 		}, {
 			data: "context",
 			render: function(data, type, row) {

+ 9 - 3
api/vendor/nekonomokochan/php-json-logger/src/PhpJsonLogger/JsonFormatter.php

@@ -2,7 +2,7 @@
 namespace Nekonomokochan\PhpJsonLogger;
 
 use Monolog\Formatter\JsonFormatter as BaseJsonFormatter;
-
+use Ramsey\Uuid\Uuid;
 /**
  * Class JsonFormatter
  *
@@ -22,7 +22,8 @@ class JsonFormatter extends BaseJsonFormatter
             'log_level'         => $record['level_name'],
             'message'           => $record['message'],
             'channel'           => $record['channel'],
-            'trace_id'          => $record['extra']['trace_id'],
+	        'username'          => $record['extra']['trace_id'],
+	        'trace_id'          => $this->generateUuid(),
             'file'              => $record['extra']['file'],
             'line'              => $record['extra']['line'],
             'context'           => $record['context'],
@@ -55,4 +56,9 @@ class JsonFormatter extends BaseJsonFormatter
 
         return ($time - $createdTime) * 1000;
     }
-}
+    
+	private function generateUuid(): string
+	{
+		return Uuid::uuid4()->toString();
+	}
+}

+ 32 - 20
api/vendor/nekonomokochan/php-json-logger/src/PhpJsonLogger/Logger.php

@@ -69,95 +69,99 @@ class Logger extends \Monolog\Logger
      * @param $message
      * @param $context
      */
-    public function debug($message, array $context = [])
+    public function debug($message, $context = '')
     {
+	    $context = $this->formatParamToArray($context);
         $this->addDebug($message, $context);
     }
 
     /**
      * @param $message
-     * @param array $context
+     * @param $context
      */
-    public function info($message, array $context = [])
+    public function info($message, $context = '')
     {
+	    $context = $this->formatParamToArray($context);
         $this->addInfo($message, $context);
     }
 
     /**
      * @param $message
-     * @param array $context
+     * @param $context
      */
-    public function notice($message, array $context = [])
+    public function notice($message, $context = '')
     {
+	    $context = $this->formatParamToArray($context);
         $this->addNotice($message, $context);
     }
 
     /**
      * @param $message
-     * @param array $context
+     * @param $context
      */
-    public function warning($message, array $context = [])
+    public function warning($message, $context = '')
     {
+	    $context = $this->formatParamToArray($context);
         $this->addWarning($message, $context);
     }
 
     /**
      * @param \Throwable $e
-     * @param array $context
+     * @param $context
      */
-    public function error($e, array $context = [])
+    public function error($e, $context = '')
     {
         if ($this->isErrorObject($e) === false) {
             throw new \InvalidArgumentException(
                 $this->generateInvalidArgumentMessage(__METHOD__)
             );
         }
-
+	    $context = $this->formatParamToArray($context);
         $this->addError(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
     }
 
     /**
      * @param \Throwable $e
-     * @param array $context
+     * @param $context
      */
-    public function critical($e, array $context = [])
+    public function critical($e, $context = '')
     {
         if ($this->isErrorObject($e) === false) {
             throw new \InvalidArgumentException(
                 $this->generateInvalidArgumentMessage(__METHOD__)
             );
         }
-
+	    $context = $this->formatParamToArray($context);
         $this->addCritical(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
     }
 
     /**
      * @param \Throwable $e
-     * @param array $context
+     * @param $context
      */
-    public function alert($e, array $context = [])
+    public function alert($e, $context = '')
     {
         if ($this->isErrorObject($e) === false) {
             throw new \InvalidArgumentException(
                 $this->generateInvalidArgumentMessage(__METHOD__)
             );
         }
-
+	    $context = $this->formatParamToArray($context);
         $this->addAlert(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
     }
 
     /**
      * @param \Throwable $e
-     * @param array $context
+     * @param $context
      */
-    public function emergency($e, array $context = [])
+    public function emergency($e, $context = '')
     {
         if ($this->isErrorObject($e) === false) {
             throw new \InvalidArgumentException(
                 $this->generateInvalidArgumentMessage(__METHOD__)
             );
         }
-
+	    $context = $this->formatParamToArray($context);
         $this->addEmergency(get_class($e), $this->formatPhpJsonLoggerErrorsContext($e, $context));
     }
 
@@ -232,4 +236,12 @@ class Logger extends \Monolog\Logger
     {
         return 'Please give the exception class to the ' . $method;
     }
-}
+	private function formatParamToArray($value): array
+	{
+		if (is_array($value)) {
+			return $value;
+		} else {
+			return (empty($value)) ? [] : ['data' => $value];
+		}
+	}
+}

+ 1 - 1
api/vendor/nekonomokochan/php-json-logger/src/PhpJsonLogger/MonologCreator.php

@@ -85,4 +85,4 @@ trait MonologCreator
             'processors' => $processors
         ];
     }
-}
+}