Kaynağa Gözat

Fix big log files (#990)

causefx 7 yıl önce
ebeveyn
işleme
6d08150902
1 değiştirilmiş dosya ile 15 ekleme ve 2 silme
  1. 15 2
      api/functions/log-functions.php

+ 15 - 2
api/functions/log-functions.php

@@ -1,7 +1,20 @@
 <?php
+function checkLog($path)
+{
+	if (file_exists($path)) {
+		if (filesize($path) > 500000) {
+			rename($path, $path . '[' . date('Y-m-d') . '].json');
+			return false;
+		}
+		return true;
+	} else {
+		return false;
+	}
+}
+
 function writeLoginLog($username, $authType)
 {
-	if (file_exists($GLOBALS['organizrLoginLog'])) {
+	if (checkLog($GLOBALS['organizrLoginLog'])) {
 		$getLog = str_replace("\r\ndate", "date", file_get_contents($GLOBALS['organizrLoginLog']));
 		$gotLog = json_decode($getLog, true);
 	}
@@ -21,7 +34,7 @@ function writeLog($type = 'error', $message, $username = null)
 	$GLOBALS['timeExecution'] = timeExecution($GLOBALS['timeExecution']);
 	$message = $message . ' [Execution Time: ' . formatSeconds($GLOBALS['timeExecution']) . ']';
 	$username = ($username) ? $username : $GLOBALS['organizrUser']['username'];
-	if (file_exists($GLOBALS['organizrLog'])) {
+	if (checkLog($GLOBALS['organizrLog'])) {
 		$getLog = str_replace("\r\ndate", "date", file_get_contents($GLOBALS['organizrLog']));
 		$gotLog = json_decode($getLog, true);
 	}