GNOME Bugzilla – Bug 775879
g_log_default_handler should not check G_MESSAGES_DEBUG
Last modified: 2017-03-24 15:08:56 UTC
Now that g_log_default_handler ends up calling the structured log handler the g_log one should not check for G_MESSAGES_DEBUG. The reason for this is when you define G_LOG_USE_STRUCTURED and you only override the structured log handler. At this point you want to still get in your overridden handler the log messages that are coming from g_log, in fact the structured log handler already checks for G_MESSAGES_DEBUG.
Seems reasonable. Patches welcome!
Created attachment 348638 [details] [review] gmessages: Don’t check G_MESSAGES_DEBUG in old logging API Now that the old logging API forwards through to the new structured logging API, we don’t need to check the level or domain of a message against INFO_LEVELS or G_MESSAGES_DEBUG — just pass it straight through to the new structured logging API writer function.
Something like this then? I haven’t really tested it.
Review of attachment 348638 [details] [review]: Looks good.
(In reply to Ignacio Casal Quinteiro (nacho) from comment #4) > Review of attachment 348638 [details] [review] [review]: > > Looks good. Have you tested it with your project which was having problems? I haven’t got a relevant test case on hand for it, so would appreciate some real-world feedback before pushing.
Nope but on my project I basically did something like this: static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer useless) { GLogField fields[2]; int n_fields = 0; fields[n_fields].key = "MESSAGE"; fields[n_fields].value = message; fields[n_fields].length = -1; n_fields++; if (log_domain) { fields[n_fields].key = "GLIB_DOMAIN"; fields[n_fields].value = log_domain; fields[n_fields].length = -1; n_fields++; } g_log_structured_array(log_level & ~G_LOG_FLAG_FATAL, fields, n_fields); }
Shipping it.
Attachment 348638 [details] pushed as 21b6b1f - gmessages: Don’t check G_MESSAGES_DEBUG in old logging API