Add timestamp prefix to log when not using syslog.

This commit is contained in:
Joris Vink 2021-09-13 15:07:43 +02:00
parent 77848e0708
commit 450aabbea1
1 changed files with 10 additions and 0 deletions

View File

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