From: Holger Schemel Date: Wed, 8 Feb 2023 12:27:30 +0000 (+0100) Subject: changed logging to write to one single log file X-Git-Tag: 4.3.5.0~9 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9f9e4ca920d37c88d3c6e15d645e18e8b56e662a;p=rocksndiamonds.git changed logging to write to one single log file --- diff --git a/src/init.c b/src/init.c index 0f8e16e5..00b471ee 100644 --- a/src/init.c +++ b/src/init.c @@ -6443,7 +6443,7 @@ void DisplayExitMessage(char *format, va_list ap) sy += 3 * font_height; num_lines_printed = - DrawTextBuffer(sx, sy, program.log_filename[LOG_ERR_ID], font_2, + DrawTextBuffer(sx, sy, program.log_filename, font_2, line_length, line_length, max_lines, 0, BLIT_ON_BACKGROUND, TRUE, TRUE, FALSE); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index b1f4b66c..9885217c 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -41,8 +41,7 @@ // logging functions // ---------------------------------------------------------------------------- -#define DUPLICATE_LOG_OUT_TO_STDOUT TRUE -#define DUPLICATE_LOG_ERR_TO_STDERR TRUE +#define DUPLICATE_LOGGING_TO_STDOUT TRUE #if defined(PLATFORM_ANDROID) @@ -94,15 +93,15 @@ static void vprintf_log(char *format, va_list ap) static void vprintf_log_nonewline(char *format, va_list ap) { - FILE *file = program.log_file[LOG_ERR_ID]; + FILE *file = program.log_file; -#if DUPLICATE_LOG_ERR_TO_STDERR - if (file != program.log_file_default[LOG_ERR_ID]) +#if DUPLICATE_LOGGING_TO_STDOUT + if (file != program.log_file_default) { va_list ap2; va_copy(ap2, ap); - vfprintf(program.log_file_default[LOG_ERR_ID], format, ap2); + vfprintf(program.log_file_default, format, ap2); va_end(ap2); } @@ -113,17 +112,17 @@ static void vprintf_log_nonewline(char *format, va_list ap) static void vprintf_log(char *format, va_list ap) { - FILE *file = program.log_file[LOG_ERR_ID]; + FILE *file = program.log_file; char *newline = STRING_NEWLINE; -#if DUPLICATE_LOG_ERR_TO_STDERR - if (file != program.log_file_default[LOG_ERR_ID]) +#if DUPLICATE_LOGGING_TO_STDOUT + if (file != program.log_file_default) { va_list ap2; va_copy(ap2, ap); - vfprintf(program.log_file_default[LOG_ERR_ID], format, ap2); - fprintf(program.log_file_default[LOG_ERR_ID], "%s", newline); + vfprintf(program.log_file_default, format, ap2); + fprintf(program.log_file_default, "%s", newline); va_end(ap2); } @@ -196,15 +195,15 @@ void printf_line_with_prefix(char *prefix, char *line_chars, int line_length) static void vPrint(char *format, va_list ap) { - FILE *file = program.log_file[LOG_OUT_ID]; + FILE *file = program.log_file; -#if DUPLICATE_LOG_OUT_TO_STDOUT - if (file != program.log_file_default[LOG_OUT_ID]) +#if DUPLICATE_LOGGING_TO_STDOUT + if (file != program.log_file_default) { va_list ap2; va_copy(ap2, ap); - vfprintf(program.log_file_default[LOG_OUT_ID], format, ap2); + vfprintf(program.log_file_default, format, ap2); va_end(ap2); } @@ -224,7 +223,7 @@ void Print(char *format, ...) void PrintNoLog(char *format, ...) { - FILE *file = program.log_file_default[LOG_OUT_ID]; + FILE *file = program.log_file_default; va_list ap; va_start(ap, format); @@ -4185,40 +4184,31 @@ char *getLogFilename(char *basename) return getPath2(getMainUserGameDataDir(), basename); } -void OpenLogFiles(void) +void OpenLogFile(void) { - int i; - InitMainUserDataDirectory(); - for (i = 0; i < NUM_LOGS; i++) + if ((program.log_file = fopen(program.log_filename, MODE_WRITE)) == NULL) { - if ((program.log_file[i] = fopen(program.log_filename[i], MODE_WRITE)) - == NULL) - { - program.log_file[i] = program.log_file_default[i]; // reset to default - - Warn("cannot open file '%s' for writing: %s", - program.log_filename[i], strerror(errno)); - } + program.log_file = program.log_file_default; // reset to default - // output should be unbuffered so it is not truncated in a crash - setbuf(program.log_file[i], NULL); + Warn("cannot open file '%s' for writing: %s", + program.log_filename, strerror(errno)); } + + // output should be unbuffered so it is not truncated in a crash + setbuf(program.log_file, NULL); } -void CloseLogFiles(void) +void CloseLogFile(void) { - int i; - - for (i = 0; i < NUM_LOGS; i++) - if (program.log_file[i] != program.log_file_default[i]) - fclose(program.log_file[i]); + if (program.log_file != program.log_file_default) + fclose(program.log_file); } -void DumpLogFile(int nr) +void DumpLogFile(void) { - FILE *log_file = fopen(program.log_filename[nr], MODE_READ); + FILE *log_file = fopen(program.log_filename, MODE_READ); if (log_file == NULL) return; @@ -4236,7 +4226,7 @@ void NotifyUserAboutErrorFile(void) char *error_text = getStringCat2("The program was aborted due to an error; " "for details, see the following error file:" STRING_NEWLINE, - program.log_filename[LOG_ERR_ID]); + program.log_filename); MessageBox(NULL, error_text, title_text, MB_OK); #endif diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 23c30e08..13b513d8 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -295,9 +295,9 @@ void ReloadCustomArtworkList(struct ArtworkListInfo *); void FreeCustomArtworkLists(struct ArtworkListInfo *); char *getLogFilename(char *); -void OpenLogFiles(void); -void CloseLogFiles(void); -void DumpLogFile(int); +void OpenLogFile(void); +void CloseLogFile(void); +void DumpLogFile(void); void NotifyUserAboutErrorFile(void); diff --git a/src/libgame/system.c b/src/libgame/system.c index 9955f224..26c2c043 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -99,10 +99,8 @@ void InitProgramInfo(char *command_filename, program.version_string = program_version_string; - program.log_filename[LOG_OUT_ID] = getLogFilename(LOG_OUT_BASENAME); - program.log_filename[LOG_ERR_ID] = getLogFilename(LOG_ERR_BASENAME); - program.log_file[LOG_OUT_ID] = program.log_file_default[LOG_OUT_ID] = stdout; - program.log_file[LOG_ERR_ID] = program.log_file_default[LOG_ERR_ID] = stderr; + program.log_filename = getLogFilename(LOG_FILENAME); + program.log_file = program.log_file_default = stdout; program.api_thread_count = 0; @@ -170,7 +168,7 @@ void InitPlatformDependentStuff(void) // this is initialized in GetOptions(), but may already be used before options.verbose = TRUE; - OpenLogFiles(); + OpenLogFile(); int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE; @@ -182,7 +180,7 @@ void InitPlatformDependentStuff(void) void ClosePlatformDependentStuff(void) { - CloseLogFiles(); + CloseLogFile(); } void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, diff --git a/src/libgame/system.h b/src/libgame/system.h index b9a7c464..ce5f4a67 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -706,12 +706,7 @@ #define FALLBACK_TEXT_FILENAME "fallback.txt" -#define LOG_OUT_BASENAME "stdout.txt" -#define LOG_ERR_BASENAME "stderr.txt" - -#define LOG_OUT_ID 0 -#define LOG_ERR_ID 1 -#define NUM_LOGS 2 +#define LOG_FILENAME "stdout.txt" #define STRING_PARENT_DIRECTORY ".." #define STRING_TOP_DIRECTORY "/" @@ -1035,9 +1030,9 @@ struct ProgramInfo char *cookie_prefix; - char *log_filename[NUM_LOGS]; // log filenames for out/err messages - FILE *log_file[NUM_LOGS]; // log file handles for out/err files - FILE *log_file_default[NUM_LOGS]; // default log file handles (out/err) + char *log_filename; // filename for log messages + FILE *log_file; // file handle for log files + FILE *log_file_default; // default log file handle int version_super; int version_major;