]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Include error domain and code in log messages from errors
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Feb 2014 17:23:10 +0000 (17:23 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 28 Feb 2014 17:38:46 +0000 (17:38 +0000)
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@redhat.com>
docs/logging.html.in
src/util/virerror.c

index bc56420720d15b9d337fdde3e44578ec5112d14e..5ff9c157f3520dae65b04454aacb1197e967f0e8 100644 (file)
       <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>
index 74c6807cd6fb26c4c99e3c09735ca7fc6da72d93..820e1adbacedfab550d092fb46c998a92df1e13a 100644 (file)
@@ -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;
 }