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 berra...@redhat.com
---
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 08afa5c..f8c57f8 100644
--- a/docs/logging.html.in
+++ b/docs/logging.html.in
@@ -173,6 +173,10 @@
ddThe line number of the file emitting the log record/dd
dtcodeCODE_FUNC/code/dt
ddThe name of the function emitting the log record/dd
+ dtcodeLIBVIRT_DOMAIN/code/dt
+ ddThe libvirt error domain (values from virErrorDomain enum), if
LIBVIRT_SOURCE=error/dd
+ dtcodeLIBVIRT_CODE/code/dt
+ ddThe libvirt error code (values from virErrorCode enum), if
LIBVIRT_SOURCE=error/dd
/dl
h2
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 74c6807..820e1ad 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;
}
--
1.8.5.3
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list