diff options
author | Thomas Haller <thaller@redhat.com> | 2019-01-15 17:54:51 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-05 08:18:07 +0100 |
commit | db2d6a1808b6cce2f97db7bec454362e963ec9eb (patch) | |
tree | e478fa9cab2273d5cf215122939ffa7022df4432 | |
parent | eea11faf9af0906cd3f37ed057e6f246106cf936 (diff) | |
download | NetworkManager-db2d6a1808b6cce2f97db7bec454362e963ec9eb.tar.gz |
logging: cleanup type definition and global variables
First define types, then declare global variables.
Reorder the code.
-rw-r--r-- | src/nm-logging.c | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c index d73b3bb9b3..e08f4f0049 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -42,16 +42,18 @@ #include "nm-utils/nm-time-utils.h" #include "nm-errors.h" -static void -nm_log_handler (const char *log_domain, - GLogLevelFlags level, - const char *message, - gpointer ignored); +/*****************************************************************************/ -typedef struct { - NMLogDomain num; - const char *name; -} LogDesc; +/* We have more then 32 logging domains. Assert that it compiles to a 64 bit sized enum */ +G_STATIC_ASSERT (sizeof (NMLogDomain) >= sizeof (guint64)); + +/* Combined domains */ +#define LOGD_ALL_STRING "ALL" +#define LOGD_DEFAULT_STRING "DEFAULT" +#define LOGD_DHCP_STRING "DHCP" +#define LOGD_IP_STRING "IP" + +/*****************************************************************************/ typedef enum { LOG_BACKEND_GLIB, @@ -60,6 +62,11 @@ typedef enum { } LogBackend; typedef struct { + NMLogDomain num; + const char *name; +} LogDesc; + +typedef struct { const char *name; const char *level_str; @@ -75,17 +82,7 @@ typedef struct { GLogLevelFlags g_log_level; } LogLevelDesc; -NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = { - /* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); - * - * Note: LOGD_VPN_PLUGIN is special and must be disabled for - * DEBUG and TRACE levels. */ - [LOGL_INFO] = LOGD_DEFAULT, - [LOGL_WARN] = LOGD_DEFAULT, - [LOGL_ERR] = LOGD_DEFAULT, -}; - -static struct Global { +typedef struct { NMLogLevel log_level; bool uses_syslog:1; bool syslog_identifier_initialized:1; @@ -102,7 +99,11 @@ static struct Global { LogBackend log_backend; char *logging_domains_to_string; -} global = { +} Global; + +/*****************************************************************************/ + +static Global global = { /* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); */ .log_level = LOGL_INFO, .log_backend = LOG_BACKEND_GLIB, @@ -110,6 +111,18 @@ static struct Global { .prefix = "", }; +NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = { + /* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); + * + * Note: LOGD_VPN_PLUGIN is special and must be disabled for + * DEBUG and TRACE levels. */ + [LOGL_INFO] = LOGD_DEFAULT, + [LOGL_WARN] = LOGD_DEFAULT, + [LOGL_ERR] = LOGD_DEFAULT, +}; + +/*****************************************************************************/ + static 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, }, @@ -162,15 +175,6 @@ static const LogDesc domain_desc[] = { { 0 }, }; -/* We have more then 32 logging domains. Assert that it compiles to a 64 bit sized enum */ -G_STATIC_ASSERT (sizeof (NMLogDomain) >= sizeof (guint64)); - -/* Combined domains */ -#define LOGD_ALL_STRING "ALL" -#define LOGD_DEFAULT_STRING "DEFAULT" -#define LOGD_DHCP_STRING "DHCP" -#define LOGD_IP_STRING "IP" - /*****************************************************************************/ static char *_domains_to_string (gboolean include_level_override); @@ -199,7 +203,7 @@ _syslog_identifier_valid_domain (const char *domain) } static gboolean -_syslog_identifier_assert (const struct Global *gl) +_syslog_identifier_assert (const Global *gl) { g_assert (gl); g_assert (gl->syslog_identifier); @@ -209,7 +213,7 @@ _syslog_identifier_assert (const struct Global *gl) } static const char * -syslog_identifier_domain (const struct Global *gl) +syslog_identifier_domain (const Global *gl) { nm_assert (_syslog_identifier_assert (gl)); return &gl->syslog_identifier[NM_STRLEN ("SYSLOG_IDENTIFIER=")]; @@ -217,7 +221,7 @@ syslog_identifier_domain (const struct Global *gl) #if SYSTEMD_JOURNAL static const char * -syslog_identifier_full (const struct Global *gl) +syslog_identifier_full (const Global *gl) { nm_assert (_syslog_identifier_assert (gl)); return &gl->syslog_identifier[0]; |