Просмотр исходного кода

write logfile logs earlier, shorten startup banner, add uptime to logfile (#1443)

Co-authored-by: CaCO3 <caco@ruinelli.ch>
CaCO3 3 лет назад
Родитель
Сommit
45a3138d28

+ 3 - 1
code/components/jomjol_logfile/ClassLogFile.cpp

@@ -164,7 +164,9 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
                 break;
         }
         
-        logline = logline + "\t<" + loglevelString + ">\t" + message.c_str() + "\n";
+        char uptime[20];
+        snprintf(uptime, sizeof(uptime), "%8d", (uint32_t)(esp_timer_get_time()/1000/1000)); // in seconds
+        logline = "[" + std::string(uptime) + "] "  + logline + "\t<" + loglevelString + ">\t" + message + "\n";
         fputs(logline.c_str(), pFile);
         fclose(pFile);    
     } else {

+ 9 - 21
code/main/main.cpp

@@ -170,26 +170,16 @@ extern "C" void app_main(void)
         string versionFormated = "Tag: '" + std::string(GIT_TAG) + "', " + versionFormated;
     }
 
-    ESP_LOGD(TAG, "=============================================================================================");
-    ESP_LOGD(TAG, "%s", versionFormated.c_str());
-    ESP_LOGD(TAG, "=============================================================================================");
-    ESP_LOGD(TAG, "Reset reason: %s", getResetReason().c_str());
-
+    LogFile.CreateLogDirectories();
 
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "==================== Startup ====================");
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, versionFormated);
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reset reason: " + getResetReason());
 
     CheckOTAUpdate();
-
-    LogFile.CreateLogDirectories();
     CheckUpdate();
-/*
-    int mk_ret = mkdir("/sdcard/new_fd_mkdir", 0775);
-    ESP_LOGI(TAG, "mkdir ret %d", mk_ret);
-    mk_ret = mkdir("/sdcard/new_fd_mkdir/test", 0775);
-    ESP_LOGI(TAG, "mkdir ret %d", mk_ret);
-    MakeDir("/sdcard/test2");
-    MakeDir("/sdcard/test2/intern");
-*/
-
 
     char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL;
     LoadWlanFromFile("/sdcard/wlan.ini", ssid, passwd, hostname, ip, gateway, netmask, dns);
@@ -229,11 +219,9 @@ extern "C" void app_main(void)
 
     setBootTime();
 
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=============================================================================================");
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================== Main Started ============================================");
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=============================================================================================");
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, versionFormated);
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reset reason: " + getResetReason());
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "================== Main Started =================");
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
 
     if (getHTMLcommit() != std::string(GIT_REV)) {
         LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Web UI version (") + getHTMLcommit() + ") does not match firmware version (" + std::string(GIT_REV) + ") !");

+ 1 - 1
sd-card/html/edit_config_param.html

@@ -1268,7 +1268,7 @@ textarea {
 				<input type="number" id="AutoTimer_Intervall_value1" size="13" min="3" step="any">
 			</td>
 			<td style="font-size: 80%;">
-				Interval in which the number(s) are read (in minutes). If a run takes longer than this interval, the next run gets postponed until the current run completes.
+				Interval in which the number(s) are read (in minutes). If a digitalization round takes longer than this interval, the next run gets postponed until the current run completes.
 			</td>
 		</tr>
 

+ 10 - 2
sd-card/html/log.html

@@ -57,6 +57,10 @@
 
 
         function processLogLine(line, index, arr) {
+            /* Make sure the whitespaces in the uptime field get persevered */
+            uptimePart = line.slice(0, line.indexOf("]")).replace(/ /g, "&nbsp;");
+            line = uptimePart + line.slice(line.indexOf("]"))
+
             if (line.includes("&lt;WRN&gt;")) {
                 arr[index] = "<span style=\"color:#e83c00\">" + line + "</span>";
             }
@@ -66,7 +70,10 @@
             else if (line.includes("&lt;DBG&gt;")) {
                 arr[index] = "<span style=\"color:gray\">" + line + "</span>";
             }
-            
+            else {
+                arr[index] = line;
+            }
+
             arr[index] += "<br>";
         }
 
@@ -80,7 +87,8 @@
                 return res.text();
             })
             .then((log) => {
-                log = log.replace(/</g, "&lt;").replace(/>/g, "&gt;");
+                log = log.replace(/</g, "&lt;");
+                log = log.replace(/>/g, "&gt;");
                 logArr = log.split("\n");
                 logArr.forEach(processLogLine);