[PATCHES] Macros for debug levels

Christof Schmitt cs at samba.org
Tue Jun 9 14:47:54 MDT 2015


Here are the updated patches debug the debug macros. The third patch is
an example to use the macros actually in the code.

Christof
-------------- next part --------------
From b151750b4e922ceacd54046aa659088488e38cc3 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/3] 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 c0a1646214891977963ec5ef6fecaadb91d7d3b3 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/3] debug: Change syslog priority mapping to match new log level macros

This changes the mapping of internal log levels to syslog priorities to
match the previously defined helper macros. The idea is that this better
maps to the actual use of log levels in the Samba code.

unchanged
 log level     | priority
 0             | ERROR
 1             | WARNING
 2             | NOTICE

before
 log level     | priority
 3             | INFO
 4 and higher  | DEBUG

after
 log level     | priority
 3 to 5        | NOTICE
 6 to 9        | INFO
 10 and higher | DEBUG

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 lib/util/debug.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 44338c5..dce3292 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -106,14 +106,19 @@ static struct {
 static int debug_level_to_priority(int level)
 {
 	/*
-	 * map debug levels to syslog() priorities note that not all
-	 * DEBUG(0, ...) calls are necessarily errors
+	 * map debug levels to syslog() priorities
 	 */
-	static const int priority_map[4] = {
+	static const int priority_map[] = {
 		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


From 3ba42fb436bb92f983abadb9abedff02a2948134 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Tue, 9 Jun 2015 13:10:27 -0700
Subject: [PATCH 3/3] smbd: Use new debug macros in kill-client-ip

Mainly to have the new macros actually used in the code.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/smbd/process.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 72135a2..958c82b 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -2711,7 +2711,7 @@ static void msg_kill_client_ip(struct messaging_context *msg_ctx,
 	const char *ip = (char *) data->data;
 	char *client_ip;
 
-	DEBUG(10, ("Got kill request for client IP %s\n", ip));
+	DBG_DEBUG("Got kill request for client IP %s\n", ip);
 
 	client_ip = tsocket_address_inet_addr_string(sconn->remote_address,
 						     talloc_tos());
@@ -2720,8 +2720,8 @@ static void msg_kill_client_ip(struct messaging_context *msg_ctx,
 	}
 
 	if (strequal(ip, client_ip)) {
-		DEBUG(1, ("Got kill client message for %s - "
-			  "exiting immediately\n", ip));
+		DBG_WARNING("Got kill client message for %s - "
+			    "exiting immediately\n", ip);
 		exit_server_cleanly("Forced disconnect for client");
 	}
 
-- 
1.7.1



More information about the samba-technical mailing list