debug: Add ability to dump_data per debug class
authorKai Blin <kai@samba.org>
Fri, 18 Jan 2013 08:44:02 +0000 (09:44 +0100)
committerKai Blin <kai@samba.org>
Fri, 18 Jan 2013 09:58:58 +0000 (10:58 +0100)
Signed-off-by: Kai Blin <kai@samba.org>
lib/util/debug.h
lib/util/samba_util.h
lib/util/util.c

index 256641852bf3e1fa01969f2086d3307240df15b9..d864c0f4f113af604d13012d90d2ba93a69c798c 100644 (file)
@@ -159,10 +159,17 @@ extern int  *DEBUGLEVEL_CLASS;
   ( ((level) <= MAX_DEBUG_LEVEL) && \
     unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
 
+#define CHECK_DEBUGLVLC( dbgc_class, level ) \
+  ( ((level) <= MAX_DEBUG_LEVEL) && \
+    unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
+
 #define DEBUGLVL( level ) \
   ( CHECK_DEBUGLVL(level) \
    && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
 
+#define DEBUGLVLC( dbgc_class, level ) \
+  ( CHECK_DEBUGLVLC( dbgc_class, level ) \
+   && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
 
 #define DEBUG( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
index 27c2e6ed3c43f8126cbfb721bf41fe0c9d237f53..d1238b03b32b096d6dba3dfd20801d639b859493 100644 (file)
@@ -690,6 +690,14 @@ void dump_data_file(const uint8_t *buf, int len, bool omit_zero_bytes,
  */
 _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len);
 
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level for
+ * debug class dbgc_class.
+ */
+_PUBLIC_ void dump_data_dbgc(int dbgc_class, int level, const uint8_t *buf, int len);
+
 /**
  * Write dump of binary data to the log file.
  *
index d49e20e6cd5f99bc4b74edf5d8e3062d34ccfb18..5412f3d92154b9f07a397e8c417b5e7a428a623f 100644 (file)
@@ -381,6 +381,19 @@ _PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type)
        return true;
 }
 
+struct debug_channel_level {
+       int channel;
+       int level;
+};
+
+static void debugadd_channel_cb(const char *buf, void *private_data)
+{
+       struct debug_channel_level *dcl =
+               (struct debug_channel_level *)private_data;
+
+       DEBUGADDC(dcl->channel, dcl->level,("%s", buf));
+}
+
 static void debugadd_cb(const char *buf, void *private_data)
 {
        int *plevel = (int *)private_data;
@@ -499,6 +512,23 @@ _PUBLIC_ void dump_data(int level, const uint8_t *buf, int len)
        dump_data_cb(buf, len, false, debugadd_cb, &level);
 }
 
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level for
+ * debug class dbgc_class.
+ */
+_PUBLIC_ void dump_data_dbgc(int dbgc_class, int level, const uint8_t *buf, int len)
+{
+       struct debug_channel_level dcl = { dbgc_class, level };
+
+       if (!DEBUGLVLC(dbgc_class, level)) {
+               DEBUG(0, ("dbgc_class is %d\n", dbgc_class));
+               return;
+       }
+       dump_data_cb(buf, len, false, debugadd_channel_cb, &dcl);
+}
+
 /**
  * Write dump of binary data to the log file.
  *