kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 450aabbea17e0d99a563fdf35932eed23f9f0c2c
parent 77848e07088c30fac9f2a836e321d5ed0ab426cf
Author: Joris Vink <joris@coders.se>
Date:   Mon, 13 Sep 2021 15:07:43 +0200

Add timestamp prefix to log when not using syslog.

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

diff --git a/src/log.c b/src/log.c @@ -16,6 +16,7 @@ #include <sys/types.h> +#include <time.h> #include <syslog.h> #include "kore.h" @@ -129,7 +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]; va_start(args, fmt); @@ -142,6 +146,12 @@ log_print(int prio, const char *fmt, ...) break; } + time(&now); + t = localtime(&now); + + if (strftime(tbuf, sizeof(tbuf), "%y-%m-%d %H:%S:%M", t) > 0) + fprintf(fp, "%s ", tbuf); + vfprintf(fp, fmt, args); fflush(fp);