kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 41511c16836953ed50443da3c308582b07009882
parent b6ec4081d569972f5d37d0b9acb44cdb33c8f43b
Author: Joris Vink <joris@coders.se>
Date:   Tue, 14 Sep 2021 09:30:17 +0200

Log timestamps in UTC for, add milliseconds.

This is when using the normal foreground logs or a specified logfile.

Diffstat:
src/log.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/log.c b/src/log.c @@ -130,10 +130,10 @@ log_from_worker(struct kore_msg *msg, const void *data) static void log_print(int prio, const char *fmt, ...) { - struct tm *t; - time_t now; - va_list args; - char tbuf[32]; + struct tm *t; + struct timespec ts; + va_list args; + char tbuf[32]; va_start(args, fmt); @@ -146,11 +146,11 @@ log_print(int prio, const char *fmt, ...) break; } - time(&now); - t = localtime(&now); + (void)clock_gettime(CLOCK_REALTIME, &ts); + t = gmtime(&ts.tv_sec); - if (strftime(tbuf, sizeof(tbuf), "%y-%m-%d %H:%M:%S", t) > 0) - fprintf(fp, "%s ", tbuf); + if (strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", t) > 0) + fprintf(fp, "%s.%ld UTC ", tbuf, ts.tv_nsec / 1000000); vfprintf(fp, fmt, args); fflush(fp);