diff include/freeDiameter/libfdproto.h @ 1167:eaa92af9e46d

New macro LOG_SPLIT to allow dumping multi-line buffers with prefix and suffix
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 31 May 2013 18:15:05 +0200
parents e8bf101264fa
children 11724ff78638
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h	Fri May 31 17:47:36 2013 +0200
+++ b/include/freeDiameter/libfdproto.h	Fri May 31 18:15:05 2013 +0200
@@ -347,6 +347,17 @@
                (prefix), __strbuf, (suffix));										\
 }
 
+/* Split a multi-line buffer into separate calls to the LOG function. */
+#define LOG_SPLIT(printlevel, per_line_prefix, mlbuf, per_line_suffix ) {						\
+	char * __line = (mlbuf), *__next;										\
+	char * __p = (per_line_prefix), *__s = (per_line_suffix);							\
+	while ((__next = strchr(__line, '\n')) != NULL) {								\
+		LOG(printlevel, "%s%.*s%s", __p ?:"", __next - __line, __line, __s ?:"");				\
+		__line = __next + 1;											\
+	}														\
+	LOG(printlevel, "%s%s%s", __p ?:"", __line, __s ?:"");								\
+}
+
 /* Helper for function entry -- for very detailed trace of the execution */
 #define TRACE_ENTRY(_format,_args... ) \
 		LOG_A("[enter] %s(" _format ") {" #_args "}", __PRETTY_FUNCTION__, ##_args );
"Welcome to our mercurial repository"