Merge pull request #416 from folkertvanheusden/timestamp-in-logging

A possible 'fix' for issue #415
This commit is contained in:
Ronnie Sahlberg
2024-04-10 03:38:07 +10:00
committed by GitHub

View File

@@ -457,6 +457,8 @@ void logging(int level, const char *format, ...)
va_list ap;
static char message[1024];
int ret;
struct timespec ts;
struct tm tm;
if (loglevel < level) {
return;
@@ -467,6 +469,17 @@ void logging(int level, const char *format, ...)
return;
}
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
return;
}
if (!localtime_r(&ts.tv_sec, &tm)) {
return;
}
printf(" %04d-%02d-%02d %02d:%02d:%02d.%06d ",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)ts.tv_nsec / 1000);
va_start(ap, format);
ret = vsnprintf(message, 1024, format, ap);
va_end(ap);