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 <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-07-18 11:11:23 +02:00
parent 453d1aa71d
commit 19d4bda69a

View File

@@ -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 static gboolean
match_log_level (const char *level, match_log_level (const char *level,
guint32 *out_level, guint32 *out_level,
@@ -295,6 +302,8 @@ nm_logging_all_levels_to_string (void)
const char * const char *
nm_logging_domains_to_string (void) nm_logging_domains_to_string (void)
{ {
_ensure_initialized ();
if (G_UNLIKELY (!logging_domains_to_string)) { if (G_UNLIKELY (!logging_domains_to_string)) {
const LogDesc *diter; const LogDesc *diter;
GString *str; GString *str;
@@ -364,6 +373,8 @@ nm_logging_enabled (guint32 level, guint64 domain)
{ {
g_return_val_if_fail (level < LOGL_MAX, FALSE); g_return_val_if_fail (level < LOGL_MAX, FALSE);
_ensure_initialized ();
return !!(logging[level] & domain); return !!(logging[level] & domain);
} }
@@ -384,8 +395,7 @@ _nm_log (const char *loc,
g_return_if_fail (level < LOGL_MAX); g_return_if_fail (level < LOGL_MAX);
if (G_UNLIKELY (!logging_set_up)) _ensure_initialized ();
nm_logging_setup ("INFO", "DEFAULT", NULL, NULL);
if (!(logging[level] & domain)) if (!(logging[level] & domain))
return; return;