Use log lines prefixed with human readable time

Fixes: #399
Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
This commit is contained in:
Zoltán Böszörményi 2023-09-20 10:19:31 +02:00 committed by Matt Turner
parent cb8938e3d3
commit 0df31f068d

View File

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