Fix timestamps printed twice on the same line (#714)

This commit is contained in:
smallmodel 2025-04-19 21:35:53 +02:00 committed by GitHub
parent aa54e3c673
commit 42326ec708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -304,54 +304,56 @@ void QDECL Com_Printf( const char *fmt, ... ) {
//================ //================
size_t msgLen = strlen(msg); size_t msgLen = strlen(msg);
if (com_logfile_timestamps->integer) { if (msgLen > 0) {
static qboolean no_newline = qfalse; if (com_logfile_timestamps->integer) {
static qboolean no_newline = qfalse;
if (!no_newline) { if (!no_newline) {
time_t t; time_t t;
time_t t_gmt; time_t t_gmt;
struct tm tms_local; struct tm tms_local;
struct tm tms_gm; struct tm tms_gm;
double tz; double tz;
const char* tzStr; const char* tzStr;
char buffer[26]; char buffer[26];
t = time(NULL); t = time(NULL);
#ifdef WIN32 #ifdef WIN32
localtime_s(&tms_local, &t); localtime_s(&tms_local, &t);
gmtime_s(&tms_gm, &t); gmtime_s(&tms_gm, &t);
#else #else
localtime_r(&t, &tms_local); localtime_r(&t, &tms_local);
gmtime_r(&t, &tms_gm); gmtime_r(&t, &tms_gm);
#endif #endif
t_gmt = mktime(&tms_gm); t_gmt = mktime(&tms_gm);
tz = difftime(t, t_gmt) / 60.0 / 60.0; tz = difftime(t, t_gmt) / 60.0 / 60.0;
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", &tms_local); strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", &tms_local);
FS_Write("[", 1, logfile); FS_Write("[", 1, logfile);
FS_Write(buffer, strlen(buffer), logfile); FS_Write(buffer, strlen(buffer), logfile);
FS_Write(" ", 1, logfile); FS_Write(" ", 1, logfile);
if (tz >= 0) { if (tz >= 0) {
tzStr = va("UTC+%.03f", tz); tzStr = va("UTC+%.03f", tz);
} else { } else {
tzStr = va("UTC%.03f", tz); tzStr = va("UTC%.03f", tz);
} }
FS_Write(tzStr, strlen(tzStr), logfile); FS_Write(tzStr, strlen(tzStr), logfile);
FS_Write("] ", 2, logfile); FS_Write("] ", 2, logfile);
} }
if (msgLen > 1 && msg[msgLen - 1] != '\n') { if (msg[msgLen - 1] != '\n') {
// Don't write the time if the previous message has no newline // Don't write the time if the previous message has no newline
no_newline = qtrue; no_newline = qtrue;
} else { } else {
no_newline = qfalse; no_newline = qfalse;
} }
} }
//================ //================
FS_Write(msg, msgLen, logfile); FS_Write(msg, msgLen, logfile);
}
} }
} }