From b71a13df5619afbb8c825580a7019714390070b0 Mon Sep 17 00:00:00 2001 From: Lee Ballard Date: Fri, 17 Feb 2023 15:41:01 -0600 Subject: [PATCH] fix ballle98/AqualinkD#73: When running in foreground Error logs do not have time stamps --- utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils.c b/utils.c index 1113a460..b3585162 100644 --- a/utils.c +++ b/utils.c @@ -634,14 +634,14 @@ void _LOG(int16_t from, int msg_level, char *message) #endif //AQ_MANAGER if (_daemonise == FALSE) { + struct timespec tspec; + struct tm localtm; + clock_gettime(CLOCK_REALTIME, &tspec); + char timeStr[TIMESTAMP_LENGTH]; + strftime(timeStr, sizeof(timeStr), "%H:%M:%S", localtime_r(&tspec.tv_sec, &localtm)); if (msg_level == LOG_ERR) { - fprintf(stderr, "%s", message); + fprintf(stderr, "%s.%03ld %s", timeStr, tspec.tv_nsec / 1000000L, message); } else { - struct timespec tspec; - struct tm localtm; - clock_gettime(CLOCK_REALTIME, &tspec); - char timeStr[TIMESTAMP_LENGTH]; - strftime(timeStr, sizeof(timeStr), "%H:%M:%S", localtime_r(&tspec.tv_sec, &localtm)); printf("%s.%03ld %s", timeStr, tspec.tv_nsec / 1000000L, message); } }