From 8c3f1812ead7fc5078cc1742643906fbf965bccd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 1 Aug 2015 14:12:34 +0200 Subject: 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__) -- cgit v1.2.1