From 0df31f068d069b846f98b2164789adde3ebadf83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?= Date: Wed, 20 Sep 2023 10:19:31 +0200 Subject: [PATCH] Use log lines prefixed with human readable time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #399 Signed-off-by: Zoltán Böszörményi --- os/log.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/os/log.c b/os/log.c index 4bd6b7e9a..e15823046 100644 --- a/os/log.c +++ b/os/log.c @@ -612,8 +612,20 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line) #endif } else if (!inSignalContext && logFile) { - if (newline) - fprintf(logFile, "[%10.3f] ", GetTimeInMillis() / 1000.0); + if (newline) { + time_t t = time(NULL); + struct tm tm; + char fmt_tm[32]; + +#ifdef WIN32 + localtime_s(&tm, &t); +#else + localtime_r(&t, &tm); +#endif + strftime(fmt_tm, sizeof(fmt_tm) - 1, "%Y-%m-%d %H:%M:%S", &tm); + + fprintf(logFile, "[%s] ", fmt_tm); + } newline = end_line; fwrite(buf, len, 1, logFile); if (logFlush) {