GnuCash Log-levels

From GnuCash
Jump to: navigation, search

The log-levels used in GnuCash are defined in the following table. For some external libraries or modules which implement logging levels defined in those libraries are translated internally to the GnuCash levels as illustrated for the for the Qof module.

Gnucash Log Level GLib level strings QOF_LOG_LEVEL Logging MACRO [1] Action after logging
G_LOG_LEVEL_ERROR "ERROR", "error" QOF_LOG_FATAL FATAL(format,args...) Aborts the program
G_LOG_LEVEL_CRITICAL "CRIT", "crit" QOF_LOG_ERROR PERR(format, args...) Execution continues [2]
G_LOG_LEVEL_WARNING "WARN", "warn" QOF_LOG_WARNING WARN(format, args...) Execution continues
G_LOG_LEVEL_MESSAGE "MESSG", "mesg" QOF_LOG_MESSAGE g_message(format, args...) Execution continues
G_LOG_LEVEL_INFO "INFO", "info" QOF_LOG_INFO PINFO(format, args...) Execution continues
G_LOG_LEVEL_DEBUG "DEBUG", "debug" QOF_LOG_DEBUG DEBUG(format, args...)

Return to Logging.

Footnotes

  1. The Logging MACRO is what you insert into your code, where you want to output a message at the appropriate log-level to the log file created as GnuCash is running. GnuCash also defines two similar macros ENTER(format, args...) and LEAVE(format, args...) to record the entry to and exit from a C function.
    ENTER
    is placed immediately before any executable code on entry to a function and
    LEAVE
    immediately before any exit point from the function.
    The format and args in all the macros are as defined for a standard printf() function.
    The form of the PERR macro which calls the GLib logging functions is shown here:
    /** Log a serious error */
    #define PERR(format, args...) do { \
        g_log (log_module, G_LOG_LEVEL_CRITICAL, \
          "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
    } while (0)
    

    Typical messages produced in a log file by these macros looks like:

    * 23:43:24 DEBUG <gnc.import>     [gnc_gen_trans_assign_transfer_account_to_selection_cb] Entering for loop over selection
    * 23:43:24 DEBUG <gnc.import> [leave gnc_gen_trans_assign_transfer_account_to_selection_cb()] 
    * 23:43:38 DEBUG <gnc.import.aqbanking> [enter ~/gnucash/import-export/aqb/gnc-plugin-aqbanking.c:main_window_to_account()] main window 0x56164c464300
    
  2. Can be made to exit the program by seting the environment variable
    G_DEBUG=fatal-warnings gdb ./my-program
    
    or calling the Glib function
    g_log_set_always_fatal ();
    
    in your code (not very flexible).