Log desync debug output to the console as well as the file.

Be fault tolerant if the desync and/or random file cannot be created,
and write to the console.
desync-debugging
Jonathan G Rennison 9 years ago
parent d4f093ed32
commit 3a5bf2ea5e

@ -118,19 +118,21 @@ static void debug_print(const char *dbg, const char *buf)
} }
if (strcmp(dbg, "desync") == 0) { if (strcmp(dbg, "desync") == 0) {
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR); static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
if (f == nullptr) return; if (f != nullptr) {
fprintf(f, "%s%s\n", GetLogPrefix(), buf); fprintf(f, "%s%s\n", GetLogPrefix(), buf);
fflush(f); fflush(f);
}
#ifdef RANDOM_DEBUG #ifdef RANDOM_DEBUG
} else if (strcmp(dbg, "random") == 0) { } else if (strcmp(dbg, "random") == 0) {
static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR); static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
if (f == nullptr) return; if (f != nullptr) {
fprintf(f, "%s%s\n", GetLogPrefix(), buf);
fprintf(f, "%s\n", buf);
fflush(f); fflush(f);
return;
}
#endif #endif
} else { }
char buffer[512]; char buffer[512];
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf); seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
#if defined(_WIN32) #if defined(_WIN32)
@ -143,7 +145,6 @@ static void debug_print(const char *dbg, const char *buf)
NetworkAdminConsole(dbg, buf); NetworkAdminConsole(dbg, buf);
IConsoleDebug(dbg, buf); IConsoleDebug(dbg, buf);
} }
}
/** /**
* Output a debug line. * Output a debug line.

Loading…
Cancel
Save