about summary refs log tree commit diff
path: root/shared/nm-glib-aux/nm-logging-base.c
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2020-01-13 16:10:30 +0100
committerSebastien Bacher <seb128@ubuntu.com>2020-01-13 16:31:40 +0100
commit5a09f7759860f4f2a9bb01471ca8099cd705bc10 (patch)
tree3a9cffc9622d53c9196771a1c7924bceb754f118 /shared/nm-glib-aux/nm-logging-base.c
parent25691220fd27093630cf244e219b2f4f1f4e749e (diff)
parentca847639aab94434daed120c874e1100c3d75dcf (diff)
Merge remote-tracking branch 'salsa/debian/master'
Diffstat (limited to 'shared/nm-glib-aux/nm-logging-base.c')
-rw-r--r--shared/nm-glib-aux/nm-logging-base.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-logging-base.c b/shared/nm-glib-aux/nm-logging-base.c
new file mode 100644
index 00000000..47b3e993
--- /dev/null
+++ b/shared/nm-glib-aux/nm-logging-base.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: LGPL-2.1+
+
+#include "nm-default.h"
+
+#include "nm-logging-base.h"
+
+#include <syslog.h>
+
+/*****************************************************************************/
+
+const LogLevelDesc level_desc[_LOGL_N] = {
+	[LOGL_TRACE] = { "TRACE", "<trace>", LOG_DEBUG,   G_LOG_LEVEL_DEBUG,   },
+	[LOGL_DEBUG] = { "DEBUG", "<debug>", LOG_DEBUG,   G_LOG_LEVEL_DEBUG,   },
+	[LOGL_INFO]  = { "INFO",  "<info>",  LOG_INFO,    G_LOG_LEVEL_INFO,    },
+	[LOGL_WARN]  = { "WARN",  "<warn>",  LOG_WARNING, G_LOG_LEVEL_MESSAGE, },
+	[LOGL_ERR]   = { "ERR",   "<error>", LOG_ERR,     G_LOG_LEVEL_MESSAGE, },
+	[_LOGL_OFF]  = { "OFF",   NULL,      0,           0,                   },
+	[_LOGL_KEEP] = { "KEEP",  NULL,      0,           0,                   },
+};
+
+gboolean
+_nm_log_parse_level (const char  *level,
+                     NMLogLevel  *out_level)
+{
+	int i;
+
+	if (!level)
+		return FALSE;
+
+	for (i = 0; i < (int) G_N_ELEMENTS (level_desc); i++) {
+		if (!g_ascii_strcasecmp (level_desc[i].name, level)) {
+			NM_SET_OUT (out_level, i);
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}