mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Write the time before each message printed in the logfile
This commit is contained in:
parent
63c2b3642c
commit
a9ec7cff4f
1 changed files with 48 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue