Difference between revisions of "GnuCash Log-levels"
From GnuCash
(→GnuCash log-levels: several minor improvements) |
|||
Line 1: | Line 1: | ||
− | + | 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. | |
− | |||
− | 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. | ||
− | |||
{| class="wikitable" style="text-align: left;" | {| class="wikitable" style="text-align: left;" | ||
|- | |- | ||
Line 8: | Line 5: | ||
! GLib level strings | ! GLib level strings | ||
! QOF_LOG_LEVEL | ! QOF_LOG_LEVEL | ||
− | ! Logging MACRO | + | ! Logging MACRO <ref>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 | + | GnuCash also defines two similar macros <tt>ENTER(format, args...)</tt> and <tt>LEAVE(format, args...)</tt> 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: <syntaxhighlight lang="C"> | |
− | |||
− | The form of the PERR macro which calls the GLib logging functions is shown | ||
− | |||
− | <syntaxhighlight lang="C"> | ||
/** Log a serious error */ | /** Log a serious error */ | ||
#define PERR(format, args...) do { \ | #define PERR(format, args...) do { \ | ||
Line 39: | Line 21: | ||
Typical messages produced in a log file by these macros looks like: | Typical messages produced in a log file by these macros looks like: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="logtalk"> |
* 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> [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: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 | * 23:43:38 DEBUG <gnc.import.aqbanking> [enter ~/gnucash/import-export/aqb/gnc-plugin-aqbanking.c:main_window_to_account()] main window 0x56164c464300 | ||
− | </syntaxhighlight> | + | </syntaxhighlight></ref> |
+ | ! 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 <ref>Can be made to exit the program by seting the environment variable <syntaxhighlight lang="sh">G_DEBUG=fatal-warnings gdb ./my-program</syntaxhighlight> or calling the Glib function <syntaxhighlight lang="C">g_log_set_always_fatal ();</syntaxhighlight> in your code (not very flexible).</ref> | ||
+ | |- | ||
+ | | 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]]. | Return to [[Logging]]. | ||
+ | ==Footnotes== | ||
+ | <references/> |
Latest revision as of 21:41, 20 May 2023
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
- ↑ 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.
/** 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
- ↑ Can be made to exit the program by seting the environment variable or calling the Glib function
G_DEBUG=fatal-warnings gdb ./my-program
in your code (not very flexible).g_log_set_always_fatal ();