static void gnc_log_init() { if (log_to_filename != NULL) { qof_log_init_filename_special(log_to_filename); } else { /* initialize logging to our file. */ gchar *tracefilename; tracefilename = g_build_filename(g_get_tmp_dir(), "gnucash.trace", (gchar *)NULL); qof_log_init_filename(tracefilename); g_free(tracefilename); } // set a reasonable default. qof_log_set_default(QOF_LOG_WARNING); gnc_log_default(); if (gnc_is_debugging()) { qof_log_set_level("", QOF_LOG_INFO); qof_log_set_level("qof", QOF_LOG_INFO); qof_log_set_level("gnc", QOF_LOG_INFO); } { gchar *log_config_filename; log_config_filename = gnc_build_dotgnucash_path("log.conf"); if (g_file_test(log_config_filename, G_FILE_TEST_EXISTS)) qof_log_parse_log_config(log_config_filename); g_free(log_config_filename); } if (log_flags != NULL) { int i = 0; for (; log_flags[i] != NULL; i++) { QofLogLevel level; gchar **parts = NULL; gchar *log_opt = log_flags[i]; parts = g_strsplit(log_opt, "=", 2); if (parts == NULL || parts[0] == NULL || parts[1] == NULL) { g_warning("string [%s] not parseable", log_opt); continue; } level = qof_log_level_from_string(parts[1]); qof_log_set_level(parts[0], level); g_strfreev(parts); } } }
/* replicate old gnc-trace enum behaviour * * these are only here as a convenience, they could be * initialised elsewhere as appropriate. * */ void gnc_log_default(void) { qof_log_set_default(QOF_LOG_WARNING); qof_log_set_level(GNC_MOD_ROOT, QOF_LOG_WARNING); qof_log_set_level(GNC_MOD_TEST, QOF_LOG_DEBUG); }
void gnc_file_log_replay (void) { char *selected_filename; char *default_dir; char read_buf[256]; char *read_retval; GtkFileFilter *filter; FILE *log_file; char * record_start_str = "===== START"; /* NOTE: This string must match src/engine/TransLog.cpp (sans newline) */ char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t" "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t" "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled"; static char *expected_header = NULL; /* Use g_strdup_printf so we don't get accidental tab -> space conversion */ if (!expected_header) expected_header = g_strdup(expected_header_orig); qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG); ENTER(" "); /* Don't log the log replay. This would only result in redundant logs */ xaccLogDisable(); default_dir = gnc_get_default_directory(GCONF_SECTION); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, "*.log"); gtk_file_filter_add_pattern(filter, "*.[Ll][Oo][Gg]"); selected_filename = gnc_file_dialog(_("Select a .log file to replay"), g_list_prepend(NULL, filter), default_dir, GNC_FILE_DIALOG_OPEN); g_free(default_dir); if (selected_filename != NULL) { /* Remember the directory as the default. */ default_dir = g_path_get_dirname(selected_filename); gnc_set_default_directory(GCONF_SECTION, default_dir); g_free(default_dir); /*strncpy(file,selected_filename, 255);*/ DEBUG("Filename found: %s", selected_filename); if (xaccFileIsCurrentLog(selected_filename)) { g_warning("Cannot open the current log file: %s", selected_filename); gnc_error_dialog(NULL, /* Translators: %s is the file name. */ _("Cannot open the current log file: %s"), selected_filename); } else { DEBUG("Opening selected file"); log_file = g_fopen(selected_filename, "r"); if (!log_file || ferror(log_file) != 0) { int err = errno; perror("File open failed"); gnc_error_dialog(NULL, /* Translation note: * First argument is the filename, * second argument is the error. */ _("Failed to open log file: %s: %s"), selected_filename, strerror(err)); } else { if ((read_retval = fgets(read_buf, sizeof(read_buf), log_file)) == NULL) { DEBUG("Read error or EOF"); gnc_info_dialog(NULL, "%s", _("The log file you selected was empty.")); } else { if (strncmp(expected_header, read_buf, strlen(expected_header)) != 0) { PERR("File header not recognised:\n%s", read_buf); PERR("Expected:\n%s", expected_header); gnc_error_dialog(NULL, "%s", _("The log file you selected cannot be read. " "The file header was not recognized.")); } else { do { read_retval = fgets(read_buf, sizeof(read_buf), log_file); /*DEBUG("Chunk read: %s",read_retval);*/ if (strncmp(record_start_str, read_buf, strlen(record_start_str)) == 0) /* If a record started */ { process_trans_record(log_file); } } while (feof(log_file) == 0); } } fclose(log_file); } } g_free(selected_filename); } /* Start logging again */ xaccLogEnable(); LEAVE(""); }