From 0915053e97bb39d6c6f664ba68a453ed4cad7b69 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 21 Feb 2014 17:23:10 +0000 Subject: [PATCH] Include error domain and code in log messages from errors When a virError is raised, pass the error domain and code onto the systemd journald using metadata fields. This allows error messages to be queried by code eg $ journalctl LIBVIRT_CODE=43 Signed-off-by: Daniel P. Berrange --- docs/logging.html.in | 4 ++++ src/util/virerror.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/logging.html.in b/docs/logging.html.in index bc56420720..5ff9c157f3 100644 --- a/docs/logging.html.in +++ b/docs/logging.html.in @@ -173,6 +173,10 @@
The line number of the file emitting the log record
CODE_FUNC
The name of the function emitting the log record
+
LIBVIRT_DOMAIN
+
The libvirt error domain (values from virErrorDomain enum), if LIBVIRT_SOURCE="error"
+
LIBVIRT_CODE
+
The libvirt error code (values from virErrorCode enum), if LIBVIRT_SOURCE="error"

diff --git a/src/util/virerror.c b/src/util/virerror.c index 74c6807cd6..820e1adbac 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -649,6 +649,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, virErrorPtr to; char *str; int priority; + virLogMetadata meta[] = { + { .key = "LIBVIRT_DOMAIN", .s = NULL, .iv = domain }, + { .key = "LIBVIRT_CODE", .s = NULL, .iv = code }, + { .key = NULL }, + }; /* * All errors are recorded in thread local storage @@ -703,10 +708,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, priority = virErrorLevelPriority(level); if (virErrorLogPriorityFilter) priority = virErrorLogPriorityFilter(to, priority); + virLogMessage(virErrorLogPriorityFilter ? VIR_LOG_FROM_FILE : VIR_LOG_FROM_ERROR, priority, filename, linenr, funcname, - NULL, "%s", str); + meta, "%s", str); errno = save_errno; } -- 2.47.2