diff --git a/shared/nm-glib-aux/nm-logging-base.c b/shared/nm-glib-aux/nm-logging-base.c index 17ea387edd..47b3e99340 100644 --- a/shared/nm-glib-aux/nm-logging-base.c +++ b/shared/nm-glib-aux/nm-logging-base.c @@ -3,3 +3,36 @@ #include "nm-default.h" #include "nm-logging-base.h" + +#include + +/*****************************************************************************/ + +const LogLevelDesc level_desc[_LOGL_N] = { + [LOGL_TRACE] = { "TRACE", "", LOG_DEBUG, G_LOG_LEVEL_DEBUG, }, + [LOGL_DEBUG] = { "DEBUG", "", LOG_DEBUG, G_LOG_LEVEL_DEBUG, }, + [LOGL_INFO] = { "INFO", "", LOG_INFO, G_LOG_LEVEL_INFO, }, + [LOGL_WARN] = { "WARN", "", LOG_WARNING, G_LOG_LEVEL_MESSAGE, }, + [LOGL_ERR] = { "ERR", "", 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; +} diff --git a/shared/nm-glib-aux/nm-logging-base.h b/shared/nm-glib-aux/nm-logging-base.h index 09233fbbcb..3d964a6ec7 100644 --- a/shared/nm-glib-aux/nm-logging-base.h +++ b/shared/nm-glib-aux/nm-logging-base.h @@ -5,4 +5,25 @@ #include "nm-logging-fwd.h" +typedef struct { + const char *name; + const char *level_str; + + /* nm-logging uses syslog internally. Note that the three most-verbose syslog levels + * are LOG_DEBUG, LOG_INFO and LOG_NOTICE. Journal already highlights LOG_NOTICE + * as special. + * + * On the other hand, we have three levels LOGL_TRACE, LOGL_DEBUG and LOGL_INFO, + * which are regular messages not to be highlighted. For that reason, we must map + * LOGL_TRACE and LOGL_DEBUG both to syslog level LOG_DEBUG. */ + int syslog_level; + + GLogLevelFlags g_log_level; +} LogLevelDesc; + +extern const LogLevelDesc level_desc[_LOGL_N]; + +gboolean _nm_log_parse_level (const char *level, + NMLogLevel *out_level); + #endif /* __NM_LOGGING_BASE_H__ */ diff --git a/src/nm-logging.c b/src/nm-logging.c index add57e4726..34dd2797aa 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -22,6 +22,7 @@ #include #endif +#include "nm-glib-aux/nm-logging-base.h" #include "nm-glib-aux/nm-time-utils.h" #include "nm-errors.h" @@ -84,22 +85,6 @@ typedef struct { const char *name; } LogDesc; -typedef struct { - const char *name; - const char *level_str; - - /* nm-logging uses syslog internally. Note that the three most-verbose syslog levels - * are LOG_DEBUG, LOG_INFO and LOG_NOTICE. Journal already highlights LOG_NOTICE - * as special. - * - * On the other hand, we have three levels LOGL_TRACE, LOGL_DEBUG and LOGL_INFO, - * which are regular messages not to be highlighted. For that reason, we must map - * LOGL_TRACE and LOGL_DEBUG both to syslog level LOG_DEBUG. */ - int syslog_level; - - GLogLevelFlags g_log_level; -} LogLevelDesc; - typedef struct { char *logging_domains_to_string; } GlobalMain; @@ -158,16 +143,6 @@ NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = { /*****************************************************************************/ -static const LogLevelDesc level_desc[_LOGL_N] = { - [LOGL_TRACE] = { "TRACE", "", LOG_DEBUG, G_LOG_LEVEL_DEBUG, }, - [LOGL_DEBUG] = { "DEBUG", "", LOG_DEBUG, G_LOG_LEVEL_DEBUG, }, - [LOGL_INFO] = { "INFO", "", LOG_INFO, G_LOG_LEVEL_INFO, }, - [LOGL_WARN] = { "WARN", "", LOG_WARNING, G_LOG_LEVEL_MESSAGE, }, - [LOGL_ERR] = { "ERR", "", LOG_ERR, G_LOG_LEVEL_MESSAGE, }, - [_LOGL_OFF] = { "OFF", NULL, 0, 0, }, - [_LOGL_KEEP] = { "KEEP", NULL, 0, 0, }, -}; - static const LogDesc domain_desc[] = { { LOGD_PLATFORM, "PLATFORM" }, { LOGD_RFKILL, "RFKILL" }, @@ -271,14 +246,8 @@ match_log_level (const char *level, NMLogLevel *out_level, GError **error) { - int 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; - } - } + if (_nm_log_parse_level (level, out_level)) + return TRUE; g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_LEVEL, _("Unknown log level '%s'"), level);