Improve logging initialization: change file opening mode to append and add error handling

This commit is contained in:
Riley 2025-05-13 19:50:34 -05:00
parent 03b7afbabf
commit 861c05bc25

View file

@ -16,17 +16,25 @@
int main(void) {
char *log_path = malloc(256);
cwk_path_join(appdata_home_path(), "error.log", log_path, 256);
FILE *fp_e = fopen(log_path, "w");
log_add_fp(fp_e, LOG_ERROR);
FILE *fp_e = fopen(log_path, "a+");
if (fp_e) {
log_add_fp(fp_e, LOG_ERROR);
} else {
log_error("Failed to open error log file at %s", log_path);
}
free(log_path);
log_path = malloc(256);
cwk_path_join(appdata_home_path(), "debug.log", log_path, 256);
FILE *fp_d = fopen(log_path, "w");
log_add_fp(fp_d, LOG_DEBUG);
FILE *fp_d = fopen(log_path, "a+");
if (fp_d) {
log_add_fp(fp_d, LOG_DEBUG);
} else {
log_error("Failed to open debug log file at %s", log_path);
}
free(log_path);
log_debug("Logging initialized.");
setup_appdata();
log_info("Appdata path: %s", appdata_home_path());