Write the time before each message printed in the logfile

This commit is contained in:
smallmodel 2025-01-09 22:23:02 +01:00
parent 63c2b3642c
commit a9ec7cff4f
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

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