summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-10-30 12:44:36 +0100
committerThomas Haller <thaller@redhat.com>2014-10-30 14:18:16 +0100
commitf4f3f4d69b6ff89b5ec7cb9b2ca3758c149f15f5 (patch)
treeff2842a9338376cca541227188c89c7ec18d262f
parent4e404212fcd2f25131ecf1617f490e3faecbe5d6 (diff)
downloadNetworkManager-f4f3f4d69b6ff89b5ec7cb9b2ca3758c149f15f5.tar.gz
core/logging: make log level and domain a C enum
This way the compiler issues a warning when accidently switching the level and domain arguments when logging. Make LOGD_ALL and LOGD_DEFAULT members of the enum instead defining them. Previously the LOGD_ALL define included all the defined domains, hence this is no functional change. Also define the logging domain aliases as enum members (instead of preprocessor defines). Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/nm-logging.c34
-rw-r--r--src/nm-logging.h28
2 files changed, 29 insertions, 33 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c
index 32d8e539e1..c32c2d364a 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -44,27 +44,15 @@ nm_log_handler (const gchar *log_domain,
const gchar *message,
gpointer ignored);
-#define LOGD_ALL \
- (LOGD_PLATFORM | LOGD_RFKILL | LOGD_ETHER | LOGD_WIFI | LOGD_BT | LOGD_MB | \
- LOGD_DHCP4 | LOGD_DHCP6 | LOGD_PPP | LOGD_WIFI_SCAN | LOGD_IP4 | \
- LOGD_IP6 | LOGD_AUTOIP4 | LOGD_DNS | LOGD_VPN | LOGD_SHARING | \
- LOGD_SUPPLICANT | LOGD_AGENTS | LOGD_SETTINGS | LOGD_SUSPEND | \
- LOGD_CORE | LOGD_DEVICE | LOGD_OLPC | LOGD_WIMAX | \
- LOGD_INFINIBAND | LOGD_FIREWALL | LOGD_ADSL | LOGD_BOND | \
- LOGD_VLAN | LOGD_BRIDGE | LOGD_DBUS_PROPS | LOGD_TEAM | LOGD_CONCHECK | \
- LOGD_DCB | LOGD_DISPATCH)
-
-#define LOGD_DEFAULT (LOGD_ALL & ~(LOGD_WIFI_SCAN | LOGD_DBUS_PROPS))
-
-static guint32 log_level = LOGL_INFO;
+static NMLogLevel log_level = LOGL_INFO;
static char *log_domains;
-static guint64 logging[LOGL_MAX];
+static NMLogDomain logging[LOGL_MAX];
static gboolean logging_set_up;
static gboolean syslog_opened;
static char *logging_domains_to_string;
typedef struct {
- guint64 num;
+ NMLogDomain num;
const char *name;
} LogDesc;
@@ -133,7 +121,7 @@ _ensure_initialized (void)
static gboolean
match_log_level (const char *level,
- guint32 *out_level,
+ NMLogLevel *out_level,
GError **error)
{
int i;
@@ -157,8 +145,8 @@ nm_logging_setup (const char *level,
GError **error)
{
GString *unrecognized = NULL;
- guint64 new_logging[LOGL_MAX];
- guint32 new_log_level = log_level;
+ NMLogDomain new_logging[LOGL_MAX];
+ NMLogLevel new_log_level = log_level;
char **tmp, **iter;
int i;
@@ -183,8 +171,8 @@ nm_logging_setup (const char *level,
tmp = g_strsplit_set (domains, ", ", 0);
for (iter = tmp; iter && *iter; iter++) {
const LogDesc *diter;
- guint32 domain_log_level;
- guint64 bits;
+ NMLogLevel domain_log_level;
+ NMLogDomain bits;
char *p;
if (!strlen (*iter))
@@ -359,7 +347,7 @@ nm_logging_all_domains_to_string (void)
}
gboolean
-nm_logging_enabled (guint32 level, guint64 domain)
+nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
{
g_return_val_if_fail (level < LOGL_MAX, FALSE);
@@ -371,8 +359,8 @@ nm_logging_enabled (guint32 level, guint64 domain)
void
_nm_log (const char *loc,
const char *func,
- guint32 level,
- guint64 domain,
+ NMLogLevel level,
+ NMLogDomain domain,
const char *fmt,
...)
{
diff --git a/src/nm-logging.h b/src/nm-logging.h
index 31076f42e8..60ddb1e511 100644
--- a/src/nm-logging.h
+++ b/src/nm-logging.h
@@ -32,7 +32,7 @@
#include "nm-utils-internal.h"
/* Log domains */
-enum {
+typedef enum { /*< skip >*/
LOGD_NONE = 0LL,
LOGD_PLATFORM = (1LL << 0), /* Platform services */
LOGD_RFKILL = (1LL << 1),
@@ -69,14 +69,22 @@ enum {
LOGD_CONCHECK = (1LL << 32),
LOGD_DCB = (1LL << 33), /* Data Center Bridging */
LOGD_DISPATCH = (1LL << 34),
-};
-#define LOGD_DHCP (LOGD_DHCP4 | LOGD_DHCP6)
-#define LOGD_IP (LOGD_IP4 | LOGD_IP6)
-#define LOGD_HW LOGD_PLATFORM
+ __LOGD_MAX,
+ LOGD_ALL = ((__LOGD_MAX - 1LL) << 1) - 1LL,
+ LOGD_DEFAULT = LOGD_ALL & ~(
+ LOGD_DBUS_PROPS |
+ LOGD_WIFI_SCAN |
+ 0),
+
+ /* aliases: */
+ LOGD_DHCP = LOGD_DHCP4 | LOGD_DHCP6,
+ LOGD_IP = LOGD_IP4 | LOGD_IP6,
+ LOGD_HW = LOGD_PLATFORM,
+} NMLogDomain;
/* Log levels */
-enum {
+typedef enum { /*< skip >*/
LOGL_TRACE,
LOGL_DEBUG,
LOGL_INFO,
@@ -84,7 +92,7 @@ enum {
LOGL_ERR,
LOGL_MAX
-};
+} NMLogLevel;
#define nm_log_err(domain, ...) nm_log (LOGL_ERR, (domain), __VA_ARGS__)
#define nm_log_warn(domain, ...) nm_log (LOGL_WARN, (domain), __VA_ARGS__)
@@ -128,14 +136,14 @@ enum {
void _nm_log (const char *loc,
const char *func,
- guint32 level,
- guint64 domain,
+ NMLogLevel level,
+ NMLogDomain domain,
const char *fmt,
...) __attribute__((__format__ (__printf__, 5, 6)));
const char *nm_logging_level_to_string (void);
const char *nm_logging_domains_to_string (void);
-gboolean nm_logging_enabled (guint32 level, guint64 domain);
+gboolean nm_logging_enabled (NMLogLevel level, NMLogDomain domain);
const char *nm_logging_all_levels_to_string (void);
const char *nm_logging_all_domains_to_string (void);