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,19 +122,21 @@ 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]; 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(WINCE) #if defined(WINCE)
@@ -149,7 +151,6 @@ static void debug_print(const char *dbg, const char *buf)
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
IConsoleDebug(dbg, buf); IConsoleDebug(dbg, buf);
} }
}
/** /**
* Output a debug line. * Output a debug line.