Prechádzať zdrojové kódy

updated debug logger

Piotr Labudda 8 rokov pred
rodič
commit
7a662c7a03
1 zmenil súbory, kde vykonal 17 pridanie a 17 odobranie
  1. 17 17
      SE/se-lib/DebugLazyLogger.php

+ 17 - 17
SE/se-lib/DebugLazyLogger.php

@@ -1,5 +1,6 @@
 <?php
 
+// @usage: DebugLazyLogger::log($mixedArg, $type, $msg, $logFileName);
 class DebugLazyLogger {
 
 	function __construct() {
@@ -14,18 +15,6 @@ class DebugLazyLogger {
 		]) . '.log';
 	}
 
-	static function getInstance() {
-		static $instance;
-		if (!$instance) $instance = new DebugLazyLogger();
-		return $instance;
-	}
-
-	// DebugLazyLogger::log($mixedArg, $type, $msg, $logFileName);
-	static function log($mixedArg, $type, $msg) {
-		$logger = self::getInstance();
-		$logger->addLog($mixedArg, $type, $msg);
-	}
-
 	function addLog($mixedArg, $type, $msg) {
 		$microTime = date("Y-m-d H:i:s") . substr((string)microtime(), 1, 6);
 		$this->_items[] = [ $microTime, $mixedArg, $type, $msg ];
@@ -36,19 +25,30 @@ class DebugLazyLogger {
 		$firstItem = reset($this->_items);
 		foreach ($this->_items as $logItem) { // $logItem: [ $mixedArg, $type, $msg, $logFileName ]
 			list($microTime, $mixedArg, $type, $msg) = $logItem;
-			self::_log($microTime, $mixedArg, $type, $msg, $this->_logFileName);
+			self::saveLogItemToFile($microTime, $mixedArg, $type, $msg, $this->_logFileName);
 		}
 		$endSaveLog = date("Y-m-d H:i:s") . substr((string)microtime(), 1, 6);
-		self::_log($startSaveLog, $mixedArg = null, $type = 'string', $msg = "Start saving log", $this->_logFileName);
-		self::_log($endSaveLog,   $mixedArg = null, $type = 'string', $msg = "End saving log", $this->_logFileName);
-		self::_log($endSaveLog,   $mixedArg = [
+		self::saveLogItemToFile($startSaveLog, $mixedArg = null, $type = 'string', $msg = "Start saving log", $this->_logFileName);
+		self::saveLogItemToFile($endSaveLog,   $mixedArg = null, $type = 'string', $msg = "End saving log", $this->_logFileName);
+		self::saveLogItemToFile($endSaveLog,   $mixedArg = [
 			"{$firstItem[0]} diff(-----) - first log entry",
 			"{$startSaveLog} diff(" . V::milisecondsStringDiff($startSaveLog, $firstItem[0]) . ") - start saving log to file",
 			"{$endSaveLog} diff(" . V::milisecondsStringDiff($endSaveLog, $startSaveLog) . ") - end saving log to file",
 		], $type = 'array', $msg = "Summary", $this->_logFileName);
 	}
 
-	public static function _log($microTime ,$mixedArg, $type, $msg, $logFileName) {
+	static function getInstance() {
+		static $instance;
+		if (!$instance) $instance = new DebugLazyLogger();
+		return $instance;
+	}
+
+	static function log($mixedArg, $type, $msg) {
+		$logger = self::getInstance();
+		$logger->addLog($mixedArg, $type, $msg);
+	}
+
+	static function saveLogItemToFile($microTime ,$mixedArg, $type, $msg, $logFileName) {
 		$logInfo = [
 			'date' => $microTime,
 			'type' => $type,