[RFC PATCHES] Macros for debug levels
Christof Schmitt
cs at samba.org
Fri Jun 5 16:35:38 MDT 2015
Looking through the code, it is often not clear what severity or log
level a certain message should have. Severe errors use level 0, and
debug messages usually have level 10.
The attached patches introduce macros for emitting messages that match a
subset of the syslog priorities. The idea would be that going forward,
any change to a debug message could also switch to one of these macros.
Over time, that should give a more consistent usage of debug levels.
A nice cleanup would also be the removal of one pair of parenthesis.
What do others think? Would this be worthwhile?
Christof
-------------- next part --------------
From 956baff649cd859914c7bfd6464f748c6a5f152e Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 5 Jun 2015 14:45:22 -0700
Subject: [PATCH 1/2] debug: Add definitions and macros for log levels
This provides some convenience macros to use consistent log levels for
messages with different severities.
Signed-off-by: Christof Schmitt <cs at samba.org>
---
lib/util/debug.h | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 379572f..8d8f43d 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -206,6 +206,21 @@ extern int *DEBUGLEVEL_CLASS;
#define DEBUGSEP(level)\
DEBUG((level),("===============================================================\n"))
+/*
+ * Debug levels matching RFC 3164
+ */
+#define DBGLVL_ERR 0 /* error conditions */
+#define DBGLVL_WARNING 1 /* warning conditions */
+#define DBGLVL_NOTICE 3 /* normal, but significant, condition */
+#define DBGLVL_INFO 5 /* informational message */
+#define DBGLVL_DEBUG 10 /* debug-level message */
+
+#define DBG_ERR(...) DEBUG(DBGLVL_ERR, (__VA_ARGS__))
+#define DBG_WARNING(...) DEBUG(DBGLVL_WARNING, (__VA_ARGS__))
+#define DBG_NOTICE(...) DEBUG(DBGLVL_NOTICE, (__VA_ARGS__))
+#define DBG_INFO(...) DEBUG(DBGLVL_INFO, (__VA_ARGS__))
+#define DBG_DEBUG(...) DEBUG(DBGLVL_DEBUG, (__VA_ARGS__))
+
/* The following definitions come from lib/debug.c */
/** Possible destinations for the debug log (in order of precedence -
--
1.7.1
From 657dce43a32bdbe5002dc3a9d12e75837869b4e8 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 5 Jun 2015 15:09:34 -0700
Subject: [PATCH 2/2] debug: Adapt mapping to match new log level macros
Signed-off-by: Christof Schmitt <cs at samba.org>
---
lib/util/debug.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 44338c5..ea5b7ac 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -113,7 +113,13 @@ static int debug_level_to_priority(int level)
LOG_ERR, /* 0 */
LOG_WARNING, /* 1 */
LOG_NOTICE, /* 2 */
- LOG_INFO, /* 3 */
+ LOG_NOTICE, /* 3 */
+ LOG_NOTICE, /* 4 */
+ LOG_NOTICE, /* 5 */
+ LOG_INFO, /* 6 */
+ LOG_INFO, /* 7 */
+ LOG_INFO, /* 8 */
+ LOG_INFO, /* 9 */
};
int priority;
--
1.7.1
More information about the samba-technical
mailing list