Files
NetworkManager/shared/nm-glib-aux/nm-logging-base.c
Thomas Haller 40012e2aa8 shared: move log level info from core to "nm-logging-base.h"
We have our NM specific logging and log levels. Maybe we should
not have that, and instead only rely on syslog (like systemd)
or glog(). Anyway, currently we have one way and it makes sense
that this is also used outside from "src".

Move the helper function to parse log levels from string to
"nm-logging-base.h" so that we can use the same logging levels
outside of core.

This moves code that is currently GPL2+ licensed to
LGPL2.1+. However as far as I see, this code was entirely written
by Red Hat employees who would not object with this change. Also,
it's as obvious and trivial as it gets.
2019-11-28 19:20:33 +01:00

39 lines
1.1 KiB
C

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