From d3b91eb258ff7b95e7f7604d565268fa76cdb12c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 13:38:25 +0200 Subject: [PATCH 1/5] logging/trivial: rename LOGL_MAX to _LOGL_N The name LOGL_MAX was misleading, because it is not the "maximum" logging level, but the number of different levels. Rename it. --- src/nm-logging.c | 22 +++++++++++----------- src/nm-logging.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index d7b85c1d4a..82e672bb10 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -53,7 +53,7 @@ nm_log_handler (const gchar *log_domain, static NMLogLevel log_level = LOGL_INFO; static char *log_domains; -static NMLogDomain logging[LOGL_MAX]; +static NMLogDomain logging[_LOGL_N]; static gboolean logging_set_up; enum { LOG_BACKEND_GLIB, @@ -76,7 +76,7 @@ typedef struct { gboolean full_details; } LogLevelDesc; -static const LogLevelDesc level_desc[LOGL_MAX] = { +static const LogLevelDesc level_desc[_LOGL_N] = { [LOGL_TRACE] = { "TRACE", "", LOG_DEBUG, G_LOG_LEVEL_DEBUG, TRUE }, [LOGL_DEBUG] = { "DEBUG", "", LOG_INFO, G_LOG_LEVEL_DEBUG, TRUE }, [LOGL_INFO] = { "INFO", "", LOG_INFO, G_LOG_LEVEL_MESSAGE, FALSE }, @@ -149,7 +149,7 @@ match_log_level (const char *level, { int i; - for (i = 0; i < LOGL_MAX; i++) { + for (i = 0; i < _LOGL_N; i++) { if (!g_ascii_strcasecmp (level_desc[i].name, level)) { *out_level = i; return TRUE; @@ -168,7 +168,7 @@ nm_logging_setup (const char *level, GError **error) { GString *unrecognized = NULL; - NMLogDomain new_logging[LOGL_MAX]; + NMLogDomain new_logging[_LOGL_N]; NMLogLevel new_log_level = log_level; char **tmp, **iter; int i; @@ -178,7 +178,7 @@ nm_logging_setup (const char *level, logging_set_up = TRUE; - for (i = 0; i < LOGL_MAX; i++) + for (i = 0; i < _LOGL_N; i++) new_logging[i] = 0; /* levels */ @@ -255,7 +255,7 @@ nm_logging_setup (const char *level, for (i = 0; i < domain_log_level; i++) new_logging[i] &= ~bits; - for (i = domain_log_level; i < LOGL_MAX; i++) + for (i = domain_log_level; i < _LOGL_N; i++) new_logging[i] |= bits; } g_strfreev (tmp); @@ -268,7 +268,7 @@ nm_logging_setup (const char *level, g_clear_pointer (&logging_domains_to_string, g_free); log_level = new_log_level; - for (i = 0; i < LOGL_MAX; i++) + for (i = 0; i < _LOGL_N; i++) logging[i] = new_logging[i]; if (unrecognized) @@ -292,7 +292,7 @@ nm_logging_all_levels_to_string (void) int i; str = g_string_new (NULL); - for (i = 0; i < LOGL_MAX; i++) { + for (i = 0; i < _LOGL_N; i++) { if (str->len) g_string_append_c (str, ','); g_string_append (str, level_desc[i].name); @@ -335,7 +335,7 @@ nm_logging_domains_to_string (void) } /* Check if it's logging at a higher level than the default. */ if (!(diter->num & logging[log_level])) { - for (i = log_level + 1; i < LOGL_MAX; i++) { + for (i = log_level + 1; i < _LOGL_N; i++) { if (diter->num & logging[i]) { g_string_append_printf (str, ":%s", level_desc[i].name); break; @@ -374,7 +374,7 @@ nm_logging_all_domains_to_string (void) gboolean nm_logging_enabled (NMLogLevel level, NMLogDomain domain) { - g_return_val_if_fail (level < LOGL_MAX, FALSE); + g_return_val_if_fail (level < _LOGL_N, FALSE); _ensure_initialized (); @@ -423,7 +423,7 @@ _nm_log_impl (const char *file, char *fullmsg = NULL; GTimeVal tv; - if ((guint) level >= LOGL_MAX) + if ((guint) level >= _LOGL_N) g_return_if_reached (); _ensure_initialized (); diff --git a/src/nm-logging.h b/src/nm-logging.h index 6af672844d..9fbe62721d 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -90,7 +90,7 @@ typedef enum { /*< skip >*/ LOGL_WARN, LOGL_ERR, - LOGL_MAX + _LOGL_N, /* the number of logging levels */ } NMLogLevel; #define nm_log_err(domain, ...) nm_log (LOGL_ERR, (domain), __VA_ARGS__) From 655b85bfea2c8e4594c6da304c844da64c0faa4d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 14:15:44 +0200 Subject: [PATCH 2/5] logging: replace using _LOGL_N by G_N_ELEMENTS() At various places we used _LOGL_N to check the index before accessing one of our static arrays. Instead use G_N_ELEMENTS(). --- src/nm-logging.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index 82e672bb10..a98972caa4 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -149,7 +149,7 @@ match_log_level (const char *level, { int i; - for (i = 0; i < _LOGL_N; i++) { + for (i = 0; i < G_N_ELEMENTS (level_desc); i++) { if (!g_ascii_strcasecmp (level_desc[i].name, level)) { *out_level = i; return TRUE; @@ -168,7 +168,7 @@ nm_logging_setup (const char *level, GError **error) { GString *unrecognized = NULL; - NMLogDomain new_logging[_LOGL_N]; + NMLogDomain new_logging[G_N_ELEMENTS (logging)]; NMLogLevel new_log_level = log_level; char **tmp, **iter; int i; @@ -178,7 +178,7 @@ nm_logging_setup (const char *level, logging_set_up = TRUE; - for (i = 0; i < _LOGL_N; i++) + for (i = 0; i < G_N_ELEMENTS (new_logging); i++) new_logging[i] = 0; /* levels */ @@ -268,7 +268,7 @@ nm_logging_setup (const char *level, g_clear_pointer (&logging_domains_to_string, g_free); log_level = new_log_level; - for (i = 0; i < _LOGL_N; i++) + for (i = 0; i < G_N_ELEMENTS (new_logging); i++) logging[i] = new_logging[i]; if (unrecognized) @@ -292,7 +292,7 @@ nm_logging_all_levels_to_string (void) int i; str = g_string_new (NULL); - for (i = 0; i < _LOGL_N; i++) { + for (i = 0; i < G_N_ELEMENTS (level_desc); i++) { if (str->len) g_string_append_c (str, ','); g_string_append (str, level_desc[i].name); @@ -335,7 +335,7 @@ nm_logging_domains_to_string (void) } /* Check if it's logging at a higher level than the default. */ if (!(diter->num & logging[log_level])) { - for (i = log_level + 1; i < _LOGL_N; i++) { + for (i = log_level + 1; i < G_N_ELEMENTS (logging); i++) { if (diter->num & logging[i]) { g_string_append_printf (str, ":%s", level_desc[i].name); break; @@ -374,7 +374,8 @@ nm_logging_all_domains_to_string (void) gboolean nm_logging_enabled (NMLogLevel level, NMLogDomain domain) { - g_return_val_if_fail (level < _LOGL_N, FALSE); + if ((guint) level >= G_N_ELEMENTS (logging)) + g_return_val_if_reached (FALSE); _ensure_initialized (); @@ -423,7 +424,7 @@ _nm_log_impl (const char *file, char *fullmsg = NULL; GTimeVal tv; - if ((guint) level >= _LOGL_N) + if ((guint) level >= G_N_ELEMENTS (logging)) g_return_if_reached (); _ensure_initialized (); From 8c3f1812ead7fc5078cc1742643906fbf965bccd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 14:12:34 +0200 Subject: [PATCH 3/5] logging: support an "OFF" logging level The only way to disable logging for a domain entirely is to omit the domain from the "domains" list. For example: "level=INFO, domains=PLATFORM,..." Now add an explicit level "OFF" to facilitate configuration like: "level=INFO, domains=ALL,WIFI_SCAN:OFF" It also supports "level=OFF, domains=PLATFORM:INFO" but this is for the most part equivalent to "level=INFO, domains=PLATFORM" --- clients/cli/nmcli-completion | 2 +- man/NetworkManager.conf.xml.in | 4 ++-- src/nm-logging.c | 13 ++++++++----- src/nm-logging.h | 6 +++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/clients/cli/nmcli-completion b/clients/cli/nmcli-completion index eb352d5269..4a55f3dbc6 100644 --- a/clients/cli/nmcli-completion +++ b/clients/cli/nmcli-completion @@ -306,7 +306,7 @@ _nmcli_compl_ARGS() case "${words[0]}" in level) if [[ "${#words[@]}" -eq 2 ]]; then - _nmcli_list "ERR WARN INFO DEBUG TRACE" + _nmcli_list "OFF ERR WARN INFO DEBUG TRACE" return 0 fi ;; diff --git a/man/NetworkManager.conf.xml.in b/man/NetworkManager.conf.xml.in index 850e772fc1..30faab4d54 100644 --- a/man/NetworkManager.conf.xml.in +++ b/man/NetworkManager.conf.xml.in @@ -396,7 +396,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth level The default logging verbosity level. - One of ERR, + One of OFF, ERR, WARN, INFO, DEBUG, TRACE. The ERR level logs only critical errors. WARN logs warnings that may @@ -419,7 +419,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth ALL, DEFAULT, DHCP, IP. You can specify per-domain log level overrides by adding a colon and a log level to any domain. E.g., - "WIFI:DEBUG". + "WIFI:DEBUG,WIFI_SCAN:OFF". Domain descriptions: diff --git a/src/nm-logging.c b/src/nm-logging.c index a98972caa4..2398e8ae73 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -53,7 +53,7 @@ nm_log_handler (const gchar *log_domain, static NMLogLevel log_level = LOGL_INFO; static char *log_domains; -static NMLogDomain logging[_LOGL_N]; +static NMLogDomain logging[_LOGL_N_REAL]; static gboolean logging_set_up; enum { LOG_BACKEND_GLIB, @@ -82,6 +82,7 @@ static const LogLevelDesc level_desc[_LOGL_N] = { [LOGL_INFO] = { "INFO", "", LOG_INFO, G_LOG_LEVEL_MESSAGE, FALSE }, [LOGL_WARN] = { "WARN", "", LOG_WARNING, G_LOG_LEVEL_WARNING, FALSE }, [LOGL_ERR] = { "ERR", "", LOG_ERR, G_LOG_LEVEL_WARNING, TRUE }, + [_LOGL_OFF] = { "OFF", NULL, 0, 0, FALSE }, }; static const LogDesc domain_descs[] = { @@ -253,10 +254,12 @@ nm_logging_setup (const char *level, continue; } - for (i = 0; i < domain_log_level; i++) - new_logging[i] &= ~bits; - for (i = domain_log_level; i < _LOGL_N; i++) - new_logging[i] |= bits; + for (i = 0; i < G_N_ELEMENTS (new_logging); i++) { + if (i < domain_log_level) + new_logging[i] &= ~bits; + else + new_logging[i] |= bits; + } } g_strfreev (tmp); diff --git a/src/nm-logging.h b/src/nm-logging.h index 9fbe62721d..a346a7a657 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -90,7 +90,11 @@ typedef enum { /*< skip >*/ LOGL_WARN, LOGL_ERR, - _LOGL_N, /* the number of logging levels */ + _LOGL_N_REAL, /* the number of actual logging levels */ + + _LOGL_OFF = _LOGL_N_REAL, /* special logging level that is always disabled. */ + + _LOGL_N, /* the number of logging levels including "OFF" */ } NMLogLevel; #define nm_log_err(domain, ...) nm_log (LOGL_ERR, (domain), __VA_ARGS__) From 4e26ef55c652014a7cb63c2df12925d8ee839886 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 14:35:51 +0200 Subject: [PATCH 4/5] logging: minor refactoring in nm_logging_setup() --- src/nm-logging.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index 2398e8ae73..dc3137eb5c 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -237,21 +237,21 @@ nm_logging_setup (const char *level, break; } } - } - if (!bits) { - if (!bad_domains) { - g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN, - _("Unknown log domain '%s'"), *iter); - return FALSE; + if (!bits) { + if (!bad_domains) { + g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN, + _("Unknown log domain '%s'"), *iter); + return FALSE; + } + + if (unrecognized) + g_string_append (unrecognized, ", "); + else + unrecognized = g_string_new (NULL); + g_string_append (unrecognized, *iter); + continue; } - - if (unrecognized) - g_string_append (unrecognized, ", "); - else - unrecognized = g_string_new (NULL); - g_string_append (unrecognized, *iter); - continue; } for (i = 0; i < G_N_ELEMENTS (new_logging); i++) { From 8a4ad96ec158eba038801a2bd8267d2bcf188dac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 14:37:34 +0200 Subject: [PATCH 5/5] logging: remove dummy logging domain "NONE" "NONE" was wrongly part of @domain_descs and thus advertised via `NetworkManager --help`. But since its @num was set to LOGD_NONE (zero), it was already rejected by nm_logging_setup(). --- src/nm-logging.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index dc3137eb5c..6ee09fbf3d 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -86,7 +86,6 @@ static const LogLevelDesc level_desc[_LOGL_N] = { }; static const LogDesc domain_descs[] = { - { LOGD_NONE, "NONE" }, { LOGD_PLATFORM, "PLATFORM" }, { LOGD_RFKILL, "RFKILL" }, { LOGD_ETHER, "ETHER" },