web: Make debug func print more useful information
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Thu, 18 Oct 2012 11:35:19 +0000 (14:35 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 19 Oct 2012 07:26:29 +0000 (10:26 +0300)
The file and function name are printed in debug prints.

gweb/gweb.c

index 4c2f95c..d35179a 100644 (file)
@@ -128,18 +128,26 @@ struct _GWeb {
        gpointer debug_data;
 };
 
-static inline void debug(GWeb *web, const char *format, ...)
+#define debug(web, format, arg...)                             \
+       _debug(web, __FILE__, __func__, format, ## arg)
+
+static void _debug(GWeb *web, const char *file, const char *caller,
+                                               const char *format, ...)
 {
        char str[256];
        va_list ap;
+       int len;
 
        if (web->debug_func == NULL)
                return;
 
        va_start(ap, format);
 
-       if (vsnprintf(str, sizeof(str), format, ap) > 0)
-               web->debug_func(str, web->debug_data);
+       if ((len = snprintf(str, sizeof(str), "%s:%s() web %p ",
+                                               file, caller, web)) > 0) {
+               if (vsnprintf(str + len, sizeof(str) - len, format, ap) > 0)
+                       web->debug_func(str, web->debug_data);
+       }
 
        va_end(ap);
 }