From 56b35e42d570e4505081c2f1a9f8bc94704c7045 Mon Sep 17 00:00:00 2001 From: the xhr Date: Thu, 26 Aug 2021 12:25:13 +0200 Subject: Use strftime() to have more apache like log messages --- log.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/log.c b/log.c index eb81019..6e07ccb 100644 --- a/log.c +++ b/log.c @@ -236,33 +236,31 @@ close_twind_logs(void) void log_access(const struct client_connection *cc, const char *fmt, ...) { + char tmstr[29]; struct tm tm; time_t t; t = time(NULL); tm = *localtime(&t); - user_log(0, "%s - - [%d/%d/%d:%d:%d:%d %s] %s", cc->client_addr, - tm.tm_mday, tm.tm_mon, tm.tm_year+1900, - tm.tm_hour, tm.tm_min, tm.tm_sec, - tm.tm_zone, fmt); + strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm); + + user_log(0, "%s - - [%s] %s", cc->client_addr, tmstr, fmt); } void log_error(const struct client_connection *cc, const char *fmt, ...) { + char tmstr[29]; struct tm tm; time_t t; t = time(NULL); tm = *localtime(&t); + strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm); - user_log(1, "[%d/%d/%d:%d:%d:%d %s] [error] [client %s] %s", - tm.tm_mday, tm.tm_mon, tm.tm_year+1900, - tm.tm_hour, tm.tm_min, tm.tm_sec, - tm.tm_zone, - cc->client_addr, - fmt); + user_log(1, "[%s] [error] [client %s] %s", tmstr, + cc->client_addr, fmt); } void -- cgit v1.2.3