commit b33425827e3b96fa5f0ee2b7892fb5782c9b7879 from: Omar Polo date: Wed Apr 14 14:52:47 2021 UTC print the datetime when logging to stderr commit - 89541eeec019626df4651f44b90df6a31a844dab commit + b33425827e3b96fa5f0ee2b7892fb5782c9b7879 blob - 519a32652016348cfde31049e08ba9f274722933 blob + 9978df471e393d5c2de98dfd67ce0a4daaa4df9d --- ChangeLog +++ ChangeLog @@ -1,3 +1,7 @@ +2021-04-14 Omar Polo + + * log.c (handle_imsg_log): print the datetime when logging to stderr + 2021-04-13 Omar Polo * ex.c (launch_cgi): define TLS_VERSION, TLS_CIPHER and TLS_CIPHER_STRENGTH for CGI scripts blob - 2ff21587cd8edca98f45ca03c02c49f6ae74e139 blob + d41c9e3b4e212f28b65d6d5c2decaa8e172210be --- log.c +++ log.c @@ -27,6 +27,7 @@ #include #include #include +#include static struct event imsgev; @@ -38,6 +39,19 @@ static imsg_handlerfn *handlers[] = { [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, ...) @@ -47,6 +61,7 @@ fatal(const char *fmt, ...) va_start(ap, fmt); if (conf.foreground) { + print_date(); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } else @@ -249,9 +264,10 @@ handle_imsg_log(struct imsgbuf *ibuf, struct imsg *ims 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); }