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.
This commit is contained in:
Jonathan G Rennison
2015-09-27 15:09:11 +01:00
parent 106c44ac48
commit 60d15aa755

View File

@@ -122,33 +122,34 @@ static void debug_print(const char *dbg, const char *buf)
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
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 == NULL) return; if (f != NULL) {
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 == NULL) return; if (f != NULL) {
fprintf(f, "%s\n", buf);
fprintf(f, "%s\n", buf); fflush(f);
fflush(f); return;
}
#endif #endif
} else { }
char buffer[512];
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf); char buffer[512];
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
#if defined(WINCE) #if defined(WINCE)
NKDbgPrintfW(OTTD2FS(buffer)); NKDbgPrintfW(OTTD2FS(buffer));
#elif defined(WIN32) || defined(WIN64) #elif defined(WIN32) || defined(WIN64)
_fputts(OTTD2FS(buffer, true), stderr); _fputts(OTTD2FS(buffer, true), stderr);
#else #else
fputs(buffer, stderr); fputs(buffer, stderr);
#endif #endif
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
NetworkAdminConsole(dbg, buf); NetworkAdminConsole(dbg, buf);
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
IConsoleDebug(dbg, buf); IConsoleDebug(dbg, buf);
}
} }
/** /**