4
0
Эх сурвалжийг харах

minimum php 7.4 needed now
added boolean variable loggerSetup
added alias function log

CauseFX 3 жил өмнө
parent
commit
e38a93bd1c

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

@@ -68,7 +68,7 @@ class Organizr
 	public $version = '2.1.2000';
 	// ===================================
 	// Quick php Version check
-	public $minimumPHP = '7.3';
+	public $minimumPHP = '7.4';
 	// ===================================
 	protected $db;
 	protected $otherDb;
@@ -84,7 +84,6 @@ class Organizr
 	public $fileHash;
 	public $cookieName;
 	public $logFile;
-	public $logger;
 	public $timeExecution;
 	public $root;
 	public $paths;
@@ -92,6 +91,8 @@ class Organizr
 	public $groupOptions;
 	public $warnings;
 	public $errors;
+	public bool $loggerSetup = false;
+	public \Nekonomokochan\PhpJsonLogger\Logger $logger;
 
 	public function __construct($updating = false)
 	{

+ 13 - 7
api/functions/log-functions.php

@@ -207,6 +207,12 @@ trait LogFunctions
 		return false;
 	}
 
+	public function log(...$params)
+	{
+		// Alias of setLoggerChannel
+		return $this->setLoggerChannel(...$params);
+	}
+
 	public function setLoggerChannel($channel = 'Organizr', $username = null)
 	{
 
@@ -216,7 +222,7 @@ trait LogFunctions
 			if ($username) {
 				$username = $this->sanitizeUserString($username);
 			}
-			if ($this->logger) {
+			if ($this->loggerSetup) {
 				if ($channel) {
 					if (strtolower($this->logger->getChannel()) !== strtolower($channel)) {
 						$this->logger->setChannel($channel);
@@ -299,21 +305,21 @@ trait LogFunctions
 				}
 			}
 			$this->logger = $loggerBuilder->build();
+			$this->loggerSetup = true;
 			return $this->logger;
 		} catch (Exception $e) {
 			// nothing so far
-			$this->logger = null;
 			return $this->logger;
 		}
-		/* setup:
+		/*
+		Setup:
 		set the log channel before you send log (You can set an optional Username (2nd Variable) | If user is logged already logged in, it will use their username):
-		$this->setLoggerChannel('Plex Homepage');
 		normal log:
-		$this->logger->info('test');
+		$this->log('Plex Homepage')->info('test');
 		normal log with context ($context must be an array):
-		$this->logger->info('test', $context);
+		$this->log('Plex Homepage')->info('test', $context);
 		exception:
-		$this->logger->critical($exception, $context);
+		$this->log('Plex Homepage')->critical($exception, $context);
 		*/
 	}