[pulseaudio-commits] r1271 - in /trunk/src/pulsecore: log.c log.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Aug 18 14:26:01 PDT 2006


Author: lennart
Date: Fri Aug 18 23:26:01 2006
New Revision: 1271

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1271&root=pulseaudio&view=rev
Log:
rework logging subsystem, to implicitly include __FILE__ in pa_log() calls. In addition we now record the line numbers and function names of pa_log calls. However, those are only shown If $PULSE_LOG_META is set.

Modified:
    trunk/src/pulsecore/log.c
    trunk/src/pulsecore/log.h

Modified: trunk/src/pulsecore/log.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/log.c?rev=1271&root=pulseaudio&r1=1270&r2=1271&view=diff
==============================================================================
--- trunk/src/pulsecore/log.c (original)
+++ trunk/src/pulsecore/log.c Fri Aug 18 23:26:01 2006
@@ -35,12 +35,14 @@
 
 #include <pulse/utf8.h>
 #include <pulse/xmalloc.h>
+#include <pulse/util.h>
 
 #include <pulsecore/core-util.h>
 
 #include "log.h"
 
 #define ENV_LOGLEVEL "PULSE_LOG"
+#define ENV_LOGMETA "PULSE_LOG_META"
 
 static char *log_ident = NULL, *log_ident_local = NULL;
 static pa_log_target_t log_target = PA_LOG_STDERR;
@@ -80,11 +82,19 @@
     user_log_func = func;
 }
 
-void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap) {
+void pa_log_levelv_meta(
+        pa_log_level_t level,
+        const char*file,
+        int line,
+        const char *func,
+        const char *format,
+        va_list ap) {
+    
     const char *e;
-    char *text, *t, *n;
+    char *text, *t, *n, *location = pa_xstrdup("");
     
     assert(level < PA_LOG_LEVEL_MAX);
+    assert(format);
 
     if ((e = getenv(ENV_LOGLEVEL)))
         maximal_level = atoi(e);
@@ -93,6 +103,11 @@
         return;
 
     text = pa_vsprintf_malloc(format, ap);
+
+    if (getenv(ENV_LOGMETA) && file && line > 0 && func)
+        location = pa_sprintf_malloc("[%s:%i %s()] ", file, line, func);
+    else if (file)
+        location = pa_sprintf_malloc("%s: ", pa_path_get_filename(file));
 
     if (!pa_utf8_valid(text))
         pa_log_level(level, __FILE__": invalid UTF-8 string following below:");
@@ -126,9 +141,9 @@
 
                 local_t = pa_utf8_to_locale(t);
                 if (!local_t)
-                    fprintf(stderr, "%s%s%s\n", prefix, t, suffix);
+                    fprintf(stderr, "%s%s%s%s\n", location, prefix, t, suffix);
                 else {
-                    fprintf(stderr, "%s%s%s\n", prefix, local_t, suffix);
+                    fprintf(stderr, "%s%s%s%s\n", location, prefix, local_t, suffix);
                     pa_xfree(local_t);
                 }
 
@@ -143,9 +158,9 @@
 
                 local_t = pa_utf8_to_locale(t);
                 if (!local_t)
-                    syslog(level_to_syslog[level], "%s", t);
+                    syslog(level_to_syslog[level], "%s%s", location, t);
                 else {
-                    syslog(level_to_syslog[level], "%s", local_t);
+                    syslog(level_to_syslog[level], "%s%s", location, local_t);
                     pa_xfree(local_t);
                 }
 
@@ -154,9 +169,15 @@
             }
 #endif
                 
-            case PA_LOG_USER: 
-                user_log_func(level, t);
+            case PA_LOG_USER: {
+                char *x;
+
+                x = pa_sprintf_malloc("%s%s", location, t);
+                user_log_func(level, x);
+                pa_xfree(x);
+                
                 break;
+            }
                 
             case PA_LOG_NULL:
             default:
@@ -165,47 +186,29 @@
     }
 
     pa_xfree(text);
-
+    pa_xfree(location);
+}
+
+void pa_log_level_meta(
+        pa_log_level_t level,
+        const char*file,
+        int line,
+        const char *func,
+        const char *format, ...) {
+    
+    va_list ap;
+    va_start(ap, format);
+    pa_log_levelv_meta(level, file, line, func, format, ap);
+    va_end(ap);
+}
+
+void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap) {
+    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap);
 }
 
 void pa_log_level(pa_log_level_t level, const char *format, ...) {
     va_list ap;
     va_start(ap, format);
-    pa_log_levelv(level, format, ap);
+    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap);
     va_end(ap);
 }
-
-void pa_log_debug(const char *format, ...) {
-    va_list ap;
-    va_start(ap, format);
-    pa_log_levelv(PA_LOG_DEBUG, format, ap);
-    va_end(ap);
-}
-
-void pa_log_info(const char *format, ...) {
-    va_list ap;
-    va_start(ap, format);
-    pa_log_levelv(PA_LOG_INFO, format, ap);
-    va_end(ap);
-}
-
-void pa_log_notice(const char *format, ...) {
-    va_list ap;
-    va_start(ap, format);
-    pa_log_levelv(PA_LOG_INFO, format, ap);
-    va_end(ap);
-}
-
-void pa_log_warn(const char *format, ...) {
-    va_list ap;
-    va_start(ap, format);
-    pa_log_levelv(PA_LOG_WARN, format, ap);
-    va_end(ap);
-}
-
-void pa_log_error(const char *format, ...) {
-    va_list ap;
-    va_start(ap, format);
-    pa_log_levelv(PA_LOG_ERROR, format, ap);
-    va_end(ap);
-}

Modified: trunk/src/pulsecore/log.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/log.h?rev=1271&root=pulseaudio&r1=1270&r2=1271&view=diff
==============================================================================
--- trunk/src/pulsecore/log.h (original)
+++ trunk/src/pulsecore/log.h Fri Aug 18 23:26:01 2006
@@ -23,6 +23,7 @@
 ***/
 
 #include <stdarg.h>
+#include <stdlib.h>
 #include <pulsecore/gccmacro.h>
 
 /* A simple logging subsystem */
@@ -53,16 +54,50 @@
 /* Minimal log level */
 void pa_log_set_maximal_level(pa_log_level_t l);
 
-/* Do a log line */
-void pa_log_debug(const char *format, ...)  PA_GCC_PRINTF_ATTR(1,2);
-void pa_log_info(const char *format, ...)  PA_GCC_PRINTF_ATTR(1,2);
-void pa_log_notice(const char *format, ...)  PA_GCC_PRINTF_ATTR(1,2);
-void pa_log_warn(const char *format, ...)  PA_GCC_PRINTF_ATTR(1,2);
-void pa_log_error(const char *format, ...)  PA_GCC_PRINTF_ATTR(1,2);
+void pa_log_level_meta(
+        pa_log_level_t level,
+        const char*file,
+        int line,
+        const char *func,
+        const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
+void pa_log_levelv_meta(
+        pa_log_level_t level,
+        const char*file,
+        int line,
+        const char *func,
+        const char *format,
+        va_list ap);
 
 void pa_log_level(pa_log_level_t level, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
+void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap);
 
-void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap);
+#if __STDC_VERSION__ >= 199901L
+
+/* ISO varargs available */
+
+#define pa_log_debug(...)  pa_log_level_meta(PA_LOG_DEBUG,  __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define pa_log_info(...)   pa_log_level_meta(PA_LOG_INFO,   __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define pa_log_notice(...) pa_log_level_meta(PA_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define pa_log_warn(...)   pa_log_level_meta(PA_LOG_WARN,   __FILE__, __LINE__, __func__, __VA_ARGS__)
+#define pa_log_error(...)  pa_log_level_meta(PA_LOG_ERROR,  __FILE__, __LINE__, __func__, __VA_ARGS__)
+
+#else
+
+#define LOG_FUNC(suffix, level) \
+PA_GCC_UNUSED static void pa_log_##suffix(const char *format, ...) { \
+    va_list ap; \
+    va_start(ap, format); \
+    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); \
+    va_end(ap); \
+}
+
+LOG_FUNC(debug, PA_LOG_DEBUG)
+LOG_FUNC(info, PA_LOG_INFO)
+LOG_FUNC(notice, PA_LOG_NOTICE)
+LOG_FUNC(warn, PA_LOG_WARN)
+LOG_FUNC(error, PA_LOG_ERROR)
+
+#endif
 
 #define pa_log pa_log_error
 




More information about the pulseaudio-commits mailing list