summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-11-17 14:38:36 +0100
committerThomas Haller <thaller@redhat.com>2023-12-12 20:16:32 +0100
commit5c08fa2776cfb17a8ef900dd30ef5d4d66bdf78a (patch)
tree333ea8856dc7b01c49efb91e1c4ec7563183a0a9
parente5aed28b8e39dce30a8efeefe7ab66f4ad655932 (diff)
libnm: refactor levels for LIBNM_CLIENT_DEBUG
Previously, it was odd. The enum values like NML_DBUS_LOG_LEVEL_DEBUG were actually the bit mask of all the levels "debug", "warn" and "error". On the other hand, when parsing _nml_dbus_log_level, that variable only contained the flags that were exactly requested. E.g. when setting LIBNM_CLIENT_DEBUG=trace, then _nml_dbus_log_level only contained the trace flag 0x02. That was useful, because with "LIBNM_CLIENT_DEBUG=warn,trace" the "warn" flag was not redundant, it was used to enable printing via g_warning(). That was confusing. Now, "LIBNM_CLIENT_DEBUG=warn,trace" is the same as "LIBNM_CLIENT_DEBUG=trace". To enable printing via g_warning(), use "LIBNM_CLIENT_DEBUG=WARN,trace". With this, we don't need this backward representation of the flags. Invert it. The level enums are now just single bits.
-rw-r--r--src/libnm-client-impl/nm-libnm-utils.c6
-rw-r--r--src/libnm-client-impl/nm-libnm-utils.h22
2 files changed, 18 insertions, 10 deletions
diff --git a/src/libnm-client-impl/nm-libnm-utils.c b/src/libnm-client-impl/nm-libnm-utils.c
index 35acb0a0f4..fea3c3af38 100644
--- a/src/libnm-client-impl/nm-libnm-utils.c
+++ b/src/libnm-client-impl/nm-libnm-utils.c
@@ -151,6 +151,12 @@ _nml_dbus_log(NMLDBusLogLevel level, gboolean use_stdout, const char *fmt, ...)
gint64 ts;
pid_t pid;
+ nm_assert(NM_IN_SET(level,
+ NML_DBUS_LOG_LEVEL_TRACE,
+ NML_DBUS_LOG_LEVEL_DEBUG,
+ NML_DBUS_LOG_LEVEL_WARN,
+ NML_DBUS_LOG_LEVEL_ERROR));
+
/* we only call _nml_dbus_log() after nml_dbus_log_enabled(), which already does
* an atomic access to the variable. Since the value is only initialized once and
* never changes, we can just access it without additional locking. */
diff --git a/src/libnm-client-impl/nm-libnm-utils.h b/src/libnm-client-impl/nm-libnm-utils.h
index 2c677f6089..d56d0fc136 100644
--- a/src/libnm-client-impl/nm-libnm-utils.h
+++ b/src/libnm-client-impl/nm-libnm-utils.h
@@ -26,9 +26,9 @@ typedef enum {
_NML_DBUS_LOG_LEVEL_INITIALIZED = 0x01,
- _NML_DBUS_LOG_LEVEL_TRACE = 0x02,
+ NML_DBUS_LOG_LEVEL_TRACE = 0x02,
- _NML_DBUS_LOG_LEVEL_DEBUG = 0x04,
+ NML_DBUS_LOG_LEVEL_DEBUG = 0x04,
/* the difference between a warning and a critical is that it results in
* g_warning() vs. g_critical() messages (with NML_DBUS_LOG_ASSERT). Note
@@ -39,21 +39,22 @@ typedef enum {
* when NetworkManager exposes something on D-Bus that breaks the current
* expectations. Usually NetworkManager should not break API, hence such
* issues are more severe. */
- _NML_DBUS_LOG_LEVEL_WARN = 0x08,
- _NML_DBUS_LOG_LEVEL_ERROR = 0x10,
+ NML_DBUS_LOG_LEVEL_WARN = 0x08,
+ NML_DBUS_LOG_LEVEL_ERROR = 0x10,
/* ANY is only relevant for nml_dbus_log_enabled() to check whether any of the
* options is on. */
NML_DBUS_LOG_LEVEL_ANY = _NML_DBUS_LOG_LEVEL_INITIALIZED,
- NML_DBUS_LOG_LEVEL_TRACE = _NML_DBUS_LOG_LEVEL_TRACE,
- NML_DBUS_LOG_LEVEL_DEBUG = _NML_DBUS_LOG_LEVEL_DEBUG | NML_DBUS_LOG_LEVEL_TRACE,
- NML_DBUS_LOG_LEVEL_WARN = _NML_DBUS_LOG_LEVEL_WARN | NML_DBUS_LOG_LEVEL_DEBUG,
- NML_DBUS_LOG_LEVEL_ERROR = _NML_DBUS_LOG_LEVEL_ERROR | NML_DBUS_LOG_LEVEL_WARN,
-
NML_DBUS_LOG_STDOUT = 0x20,
NML_DBUS_LOG_ASSERT = 0x40,
+
+ _NML_DBUS_LOG_LEVEL_ERROR = NML_DBUS_LOG_LEVEL_ERROR,
+ _NML_DBUS_LOG_LEVEL_WARN = NML_DBUS_LOG_LEVEL_WARN | _NML_DBUS_LOG_LEVEL_ERROR,
+ _NML_DBUS_LOG_LEVEL_DEBUG = NML_DBUS_LOG_LEVEL_DEBUG | _NML_DBUS_LOG_LEVEL_WARN,
+ _NML_DBUS_LOG_LEVEL_TRACE = NML_DBUS_LOG_LEVEL_TRACE | _NML_DBUS_LOG_LEVEL_DEBUG,
+
} NMLDBusLogLevel;
#undef _LOGL_TRACE
@@ -64,7 +65,6 @@ typedef enum {
#define _LOGL_TRACE NML_DBUS_LOG_LEVEL_TRACE
#define _LOGL_DEBUG NML_DBUS_LOG_LEVEL_DEBUG
-#define _LOGL_INFO NML_DBUS_LOG_LEVEL_INFO
#define _LOGL_WARN NML_DBUS_LOG_LEVEL_WARN
#define _LOGL_ERR NML_DBUS_LOG_LEVEL_ERR
@@ -90,7 +90,9 @@ nml_dbus_log_enabled_full(NMLDBusLogLevel level, gboolean *out_use_stdout)
l = _nml_dbus_log_level_init();
nm_assert(l & _NML_DBUS_LOG_LEVEL_INITIALIZED);
+
NM_SET_OUT(out_use_stdout, NM_FLAGS_HAS(l, NML_DBUS_LOG_STDOUT));
+
if (level == NML_DBUS_LOG_LEVEL_ANY) {
return NM_FLAGS_ANY(l,
NML_DBUS_LOG_LEVEL_TRACE | NML_DBUS_LOG_LEVEL_DEBUG