commit - 89541eeec019626df4651f44b90df6a31a844dab
commit + b33425827e3b96fa5f0ee2b7892fb5782c9b7879
blob - 519a32652016348cfde31049e08ba9f274722933
blob + 9978df471e393d5c2de98dfd67ce0a4daaa4df9d
--- ChangeLog
+++ ChangeLog
+2021-04-14 Omar Polo <op@omarpolo.com>
+
+ * log.c (handle_imsg_log): print the datetime when logging to stderr
+
2021-04-13 Omar Polo <op@omarpolo.com>
* ex.c (launch_cgi): define TLS_VERSION, TLS_CIPHER and TLS_CIPHER_STRENGTH for CGI scripts
blob - 2ff21587cd8edca98f45ca03c02c49f6ae74e139
blob + d41c9e3b4e212f28b65d6d5c2decaa8e172210be
--- log.c
+++ log.c
#include <stdio.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
static struct event imsgev;
[IMSG_QUIT] = handle_imsg_quit,
[IMSG_LOG] = handle_imsg_log,
};
+
+static inline void
+print_date(void)
+{
+ struct tm tminfo;
+ time_t t;
+ char buf[20];
+
+ time(&t);
+ strftime(buf, sizeof(buf), "%F %T",
+ localtime_r(&t, &tminfo));
+ fprintf(stderr, "[%s] ", buf);
+}
void
fatal(const char *fmt, ...)
va_start(ap, fmt);
if (conf.foreground) {
+ print_date();
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
} else
msg = imsg->data;
msg[datalen-1] = '\0';
- if (conf.foreground)
+ if (conf.foreground) {
+ print_date();
fprintf(stderr, "%s\n", msg);
- else
+ } else
syslog(LOG_DAEMON, "%s", msg);
}