[libvirt] [PATCH 06/12] Pass the "raw" log message to each virLogOutputFunc

Miloslav Trmač mitr at redhat.com
Thu Sep 20 18:24:05 UTC 2012


In addition to the preformatted text line, pass the raw message as well,
to allow the output functions to use a different output format.

This patch only changes the interface and callers, an output function
that takes advantage of this will follow.

Signed-off-by: Miloslav Trmač <mitr at redhat.com>
---
 src/util/logging.c | 23 ++++++++++++++---------
 src/util/logging.h |  3 ++-
 tests/testutils.c  |  1 +
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/util/logging.c b/src/util/logging.c
index 537c764..5471552 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -102,7 +102,7 @@ static void virLogOutputToFd(const char *category, int priority,
                              const char *funcname, long long linenr,
                              const char *timestamp,
                              unsigned int flags,
-                             const char *str,
+                             const char *rawstr, const char *str,
                              void *data);
 
 /*
@@ -631,7 +631,7 @@ virLogFormatString(char **msg,
 }
 
 static int
-virLogVersionString(char **msg)
+virLogVersionString(const char **rawmsg, char **msg)
 {
 #ifdef PACKAGER_VERSION
 # ifdef PACKAGER
@@ -646,6 +646,7 @@ virLogVersionString(char **msg)
     "libvirt version: " VERSION
 #endif
 
+    *rawmsg = LOG_VERSION_STRING;
     return virLogFormatString(msg, NULL, 0, VIR_LOG_INFO, LOG_VERSION_STRING);
 }
 
@@ -725,7 +726,6 @@ void virLogVMessage(const char *category, int priority, const char *funcname,
     }
 
     ret = virLogFormatString(&msg, funcname, linenr, priority, str);
-    VIR_FREE(str);
     if (ret < 0)
         goto cleanup;
 
@@ -751,38 +751,41 @@ void virLogVMessage(const char *category, int priority, const char *funcname,
     for (i = 0; i < virLogNbOutputs; i++) {
         if (priority >= virLogOutputs[i].priority) {
             if (virLogOutputs[i].logVersion) {
+                const char *rawver;
                 char *ver = NULL;
-                if (virLogVersionString(&ver) >= 0)
+                if (virLogVersionString(&rawver, &ver) >= 0)
                     virLogOutputs[i].f(category, VIR_LOG_INFO,
                                        __func__, __LINE__,
-                                       timestamp, 0, ver,
+                                       timestamp, 0, rawver, ver,
                                        virLogOutputs[i].data);
                 VIR_FREE(ver);
                 virLogOutputs[i].logVersion = false;
             }
             virLogOutputs[i].f(category, priority, funcname, linenr,
                                timestamp, filterflags,
-                               msg, virLogOutputs[i].data);
+                               str, msg, virLogOutputs[i].data);
         }
     }
     if ((virLogNbOutputs == 0) && (flags != 1)) {
         if (logVersionStderr) {
+            const char *rawver;
             char *ver = NULL;
-            if (virLogVersionString(&ver) >= 0)
+            if (virLogVersionString(&rawver, &ver) >= 0)
                 virLogOutputToFd(category, VIR_LOG_INFO,
                                  __func__, __LINE__,
-                                 timestamp, 0, ver,
+                                 timestamp, 0, rawver, ver,
                                  (void *) STDERR_FILENO);
             VIR_FREE(ver);
             logVersionStderr = false;
         }
         virLogOutputToFd(category, priority, funcname, linenr,
                          timestamp, filterflags,
-                         msg, (void *) STDERR_FILENO);
+                         str, msg, (void *) STDERR_FILENO);
     }
     virLogUnlock();
 
 cleanup:
+    VIR_FREE(str);
     VIR_FREE(msg);
     errno = saved_errno;
 }
@@ -813,6 +816,7 @@ static void virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
                              long long linenr ATTRIBUTE_UNUSED,
                              const char *timestamp,
                              unsigned int flags,
+                             const char *rawstr ATTRIBUTE_UNUSED,
                              const char *str,
                              void *data)
 {
@@ -868,6 +872,7 @@ static void virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
                                  long long linenr ATTRIBUTE_UNUSED,
                                  const char *timestamp ATTRIBUTE_UNUSED,
                                  unsigned int flags,
+                                 const char *rawstr ATTRIBUTE_UNUSED,
                                  const char *str,
                                  void *data ATTRIBUTE_UNUSED)
 {
diff --git a/src/util/logging.h b/src/util/logging.h
index 1c484bb..10ff6c9 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -90,6 +90,7 @@ typedef enum {
  * @linenr: line where the message was emitted
  * @timestamp: zero terminated string with timestamp of the message
  * @flags: flags associated with the message
+ * @rawstr: the unformatted message to log, zero terminated
  * @str: the message to log, preformatted and zero terminated
  * @data: extra output logging data
  *
@@ -99,7 +100,7 @@ typedef void (*virLogOutputFunc) (const char *category, int priority,
                                   const char *funcname, long long linenr,
                                   const char *timestamp,
                                   unsigned int flags,
-                                  const char *str,
+                                  const char *rawstr, const char *str,
                                   void *data);
 
 /**
diff --git a/tests/testutils.c b/tests/testutils.c
index 5c32f14..6978020 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -485,6 +485,7 @@ virtTestLogOutput(const char *category ATTRIBUTE_UNUSED,
                   long long lineno ATTRIBUTE_UNUSED,
                   const char *timestamp,
                   unsigned int flags,
+                  const char *rawstr ATTRIBUTE_UNUSED,
                   const char *str,
                   void *data)
 {
-- 
1.7.11.4




More information about the libvir-list mailing list