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 <berrange(a)redhat.com>
---
src/util/virerror.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
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