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:
Slider0007
2023-03-01 20:55:12 +01:00
committed by GitHub
parent 8c7e86fea4
commit d3d241c7b9
3 changed files with 31 additions and 9 deletions

View File

@@ -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;
}
}