changeset 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 5b930daeb4c1
children a4604f98adae
files include/freeDiameter/libfdproto.h libfdcore/core.c
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
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 );
--- a/libfdcore/core.c	Fri May 31 17:47:36 2013 +0200
+++ b/libfdcore/core.c	Fri May 31 18:15:05 2013 +0200
@@ -250,11 +250,11 @@
 	
 	/* Display configuration */
 	b = fd_conf_dump(&buf, &len, NULL);
-	LOG_N("%s", b ?: "Error during configuration dump...");
+	LOG_SPLIT(FD_LOG_NOTICE, NULL, b ?: "<Error during configuration dump...>", NULL);
 	
 	/* Display extensions status */
 	b = fd_ext_dump(&buf, &len, NULL, 19);
-	LOG_N("Loaded extensions: %s", b ?: "Error during extensions dump...");
+	LOG_SPLIT(FD_LOG_NOTICE, "Loaded extensions: ", b?:"<Error during extensions dump...>", NULL);
 	
 	/* Display registered triggers for FDEV_TRIGGER */
 	b = fd_event_trig_dump(&buf, &len, &offset);
"Welcome to our mercurial repository"