Custom handlers can't handle G_LOG_FLAG_RECURSION
Submitted by Marcelo Vanzin
Link to original bug (#618956)
Description
This is either a code bug or a documentation bug. In any case, the docs say this:
""" Sets the log handler for a domain and a set of log levels. To handle fatal and recursive messages the log_levels parameter must be combined with the G_LOG_FLAG_FATAL and G_LOG_FLAG_RECURSION bit flags. """
So let's try:
#define G_LOG_DOMAIN "rec" #include <glib.h> #include <stdio.h>
void mylog(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) { printf("%s:%d: %s\n", log_domain, log_level, message); if (!(log_level & G_LOG_FLAG_RECURSION)) { g_debug("recursing\n"); } }
int main(void) { g_log_set_handler(G_LOG_DOMAIN, 0XFFFF, mylog, NULL); g_warning("log message"); return 0; }
And the result:
$ ./rec rec:16: log message
(process:7608): rec-DEBUG (recursed): recursing
aborting... Aborted
So you can't really handle G_LOG_FLAG_RECURSION with a custom handler. In fact, this is what the glib code does:
if (test_level & G_LOG_FLAG_RECURSION) log_func = _g_log_fallback_handler; else log_func = g_log_domain_get_handler_L (domain, test_level, &data);
So either the library or the documentation needs to be fixed... I'd vote for fixing the code. :-)