svn commit: samba r12798 - in branches/SAMBA_4_0/source: include lib

metze at samba.org metze at samba.org
Mon Jan 9 18:25:07 GMT 2006


Author: metze
Date: 2006-01-09 18:25:06 +0000 (Mon, 09 Jan 2006)
New Revision: 12798

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=12798

Log:
print timestamps into the log file, this is not nice code,
but it works for now

metze
Modified:
   branches/SAMBA_4_0/source/include/debug.h
   branches/SAMBA_4_0/source/lib/debug.c


Changeset:
Modified: branches/SAMBA_4_0/source/include/debug.h
===================================================================
--- branches/SAMBA_4_0/source/include/debug.h	2006-01-09 17:43:48 UTC (rev 12797)
+++ branches/SAMBA_4_0/source/include/debug.h	2006-01-09 18:25:06 UTC (rev 12798)
@@ -35,15 +35,24 @@
 	void (*log_task_id)(int fd);
 };
 
+void do_debug_header(int level);
 void do_debug(const char *, ...) PRINTF_ATTRIBUTE(1,2);
 
 extern int DEBUGLEVEL;
 
 #define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
-#define DEBUG(level, body) do { if (DEBUGLVL(level)) do_debug body; } while (0)
-#define DEBUGADD(level, body) DEBUG(level, body)
+#define _DEBUG(level, body, header) do { \
+	if (DEBUGLVL(level)) { \
+		if (header) { \
+			do_debug_header(level); \
+		} \
+		do_debug body; \
+	} \
+} while (0)
+#define DEBUG(level, body) _DEBUG(level, body, True)
+#define DEBUGADD(level, body) _DEBUG(level, body, False)
 #define DEBUGC(class, level, body) DEBUG(level, body)
-#define DEBUGADDC(class, level, body) DEBUG(level, body)
+#define DEBUGADDC(class, level, body) DEBUGADD(level, body)
 #define DEBUGTAB(n) do_debug_tab(n)
 
 enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2};

Modified: branches/SAMBA_4_0/source/lib/debug.c
===================================================================
--- branches/SAMBA_4_0/source/lib/debug.c	2006-01-09 17:43:48 UTC (rev 12797)
+++ branches/SAMBA_4_0/source/lib/debug.c	2006-01-09 18:25:06 UTC (rev 12798)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
+#include "system/time.h"
 #include "dynconfig.h"
 
 /* this global variable determines what messages are printed */
@@ -44,6 +45,16 @@
   the backend for debug messages. Note that the DEBUG() macro has already
   ensured that the log level has been met before this is called
 */
+void do_debug_header(int level)
+{
+	log_timestring(level);
+	log_task_id();
+}
+
+/*
+  the backend for debug messages. Note that the DEBUG() macro has already
+  ensured that the log level has been met before this is called
+*/
 void do_debug(const char *format, ...)
 {
 	va_list ap;
@@ -59,8 +70,6 @@
 	vasprintf(&s, format, ap);
 	va_end(ap);
 
-	log_task_id();
-	
 	write(state.fd, s, strlen(s));
 	free(s);
 }
@@ -153,6 +162,24 @@
 	}
 }
 
+void log_timestring(int level)
+{
+	char *t = NULL;
+	char *s = NULL;
+
+	if (state.logtype != DEBUG_FILE) return;
+
+	t = timestring(NULL, time(NULL));
+	if (!t) return;
+
+	asprintf(&s, "[%s, %d]\n", t, level);
+	talloc_free(t);
+	if (!s) return;
+
+	write(state.fd, s, strlen(s));
+	free(s);
+}
+
 uint32_t get_task_id(void)
 {
 	if (debug_handlers.ops.get_task_id) {
@@ -167,6 +194,7 @@
 		debug_handlers.ops.log_task_id(state.fd);
 	}
 }
+
 /*
   register a set of debug handlers. 
 */



More information about the samba-cvs mailing list