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
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;