From 19d4bda69ae135d400b8778c47db8f60b11d24a0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jul 2014 11:11:23 +0200 Subject: [PATCH] core/logging: ensure that logging is always initialized Ensure that nm_logging_setup() was called for all functions where it actually makes a difference. This is especially important for nm_logging_enabled(), so that the behavior of the following is identical: nm_log_info(LOGD_CORE, "hello world"); and if (nm_logging_enabled (LOGL_INFO, LOGD_CORE)) nm_log_info(LOGD_CORE, "hello world"); Signed-off-by: Thomas Haller --- src/nm-logging.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index 470b0e382..5712b8858 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -134,6 +134,13 @@ nm_logging_error_quark (void) /************************************************************************/ +static void +_ensure_initialized () +{ + if (G_UNLIKELY (!logging_set_up)) + nm_logging_setup ("INFO", "DEFAULT", NULL, NULL); +} + static gboolean match_log_level (const char *level, guint32 *out_level, @@ -295,6 +302,8 @@ nm_logging_all_levels_to_string (void) const char * nm_logging_domains_to_string (void) { + _ensure_initialized (); + if (G_UNLIKELY (!logging_domains_to_string)) { const LogDesc *diter; GString *str; @@ -364,6 +373,8 @@ nm_logging_enabled (guint32 level, guint64 domain) { g_return_val_if_fail (level < LOGL_MAX, FALSE); + _ensure_initialized (); + return !!(logging[level] & domain); } @@ -384,8 +395,7 @@ _nm_log (const char *loc, g_return_if_fail (level < LOGL_MAX); - if (G_UNLIKELY (!logging_set_up)) - nm_logging_setup ("INFO", "DEFAULT", NULL, NULL); + _ensure_initialized (); if (!(logging[level] & domain)) return;