mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 03:56:57 +03:00
Logfile: Print start indication block after time sync (#2106)
* logfile: Print start indication after time sync * No time set at boot -> keep log_1970-01-01.txt
This commit is contained in:
@@ -15,6 +15,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Helper.h"
|
||||
#include "time_sntp.h"
|
||||
#include "../../include/defines.h"
|
||||
|
||||
static const char *TAG = "LOGFILE";
|
||||
@@ -322,13 +323,21 @@ void ClassLogFile::RemoveOldLogFile()
|
||||
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
|
||||
//ESP_LOGD(TAG, "delete log file: %s", entry->d_name);
|
||||
std::string filepath = logroot + "/" + entry->d_name;
|
||||
if ((strcmp(entry->d_name, "log_1970-01-01.txt") == 0) && getTimeWasNotSetAtBoot()) { // keep logfile log_1970-01-01.txt if time was not set at boot (some boot logs are in there)
|
||||
//ESP_LOGD(TAG, "Skip deleting this file: %s", entry->d_name);
|
||||
notDeleted++;
|
||||
}
|
||||
else {
|
||||
if (unlink(filepath.c_str()) == 0) {
|
||||
deleted++;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "can't delete file: %s", entry->d_name);
|
||||
notDeleted++;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
notDeleted++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ static const char *TAG = "SNTP";
|
||||
static std::string timeZone = "";
|
||||
static std::string timeServer = "undefined";
|
||||
static bool useNtp = true;
|
||||
static bool timeWasNotSetAtBoot = false;
|
||||
|
||||
std::string getNtpStatusText(sntp_sync_status_t status);
|
||||
static void setTimeZone(std::string _tzstring);
|
||||
@@ -59,7 +60,12 @@ std::string getCurrentTimeString(const char * frm)
|
||||
|
||||
void time_sync_notification_cb(struct timeval *tv)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is now successfully synced with NTP Server " +
|
||||
if (timeWasNotSetAtBoot) {
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "==================== Start ======================");
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "== Logs before time sync -> log_1970-01-01.txt ==");
|
||||
}
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is synced with NTP Server " +
|
||||
getServerName() + ": " + getCurrentTimeString("%Y-%m-%d %H:%M:%S"));
|
||||
}
|
||||
|
||||
@@ -111,6 +117,11 @@ bool getUseNtp(void) {
|
||||
return useNtp;
|
||||
}
|
||||
|
||||
bool getTimeWasNotSetAtBoot(void)
|
||||
{
|
||||
return timeWasNotSetAtBoot;
|
||||
}
|
||||
|
||||
|
||||
std::string getServerName(void) {
|
||||
char buf[100];
|
||||
@@ -225,6 +236,7 @@ bool setupTime() {
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "The local time is unknown, starting with " + std::string(strftime_buf));
|
||||
if (useNtp) {
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Once the NTP server provides a time, we will switch to that one");
|
||||
timeWasNotSetAtBoot = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ std::string ConvertTimeToString(time_t _time, const char * frm);
|
||||
|
||||
|
||||
bool getTimeIsSet(void);
|
||||
bool getTimeWasNotSetAtBoot(void);
|
||||
|
||||
bool getUseNtp(void);
|
||||
bool setupTime();
|
||||
|
||||
Reference in New Issue
Block a user