From a5fa3322c8ffe0a5ec4cb77f76406a6c3f61302c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 27 Sep 2012 12:45:33 +0100 Subject: [PATCH] Pass the "raw" log message to each virLogOutputFunc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In addition to the preformatted text line, pass the raw message as well, to allow the output functions to use a different output format. Signed-off-by: Miloslav Trmač Signed-off-by: Daniel P. Berrange --- 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 dc78e948d8..ae11267d78 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) { @@ -884,6 +888,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 256e81699b..584e2b404c 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 4d4f58975b..a33b10d19e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -486,6 +486,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) { -- GitLab