[PATCH v2 6/8] Include error domain and code in log messages from errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 @@
       <dd>The line number of the file emitting the log record</dd>
       <dt><code>CODE_FUNC</code></dt>
       <dd>The name of the function emitting the log record</dd>
+      <dt><code>LIBVIRT_DOMAIN</code></dt>
+      <dd>The libvirt error domain (values from virErrorDomain enum), if LIBVIRT_SOURCE="error"</dd>
+      <dt><code>LIBVIRT_CODE</code></dt>
+      <dd>The 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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]