[libvirt] [PATCH] 4/8 convert virterror to the logging infrastructure

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

 



  Basically having the debug information in one place and the errors
in another place is not very helpful, so this plugs the virterror
handling into the logging routine. mostly a bit of refactoring,
and calling virLogMessage. Just that we pass an extra flag to
virLogMessage stating it comes from the error handling level to avoid
outputting the error twice on stderr in case where there is no
output defined.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
Index: src/virterror.c
===================================================================
RCS file: /data/cvs/libxen/src/virterror.c,v
retrieving revision 1.55
diff -u -r1.55 virterror.c
--- src/virterror.c	25 Nov 2008 10:44:53 -0000	1.55
+++ src/virterror.c	17 Dec 2008 14:25:57 -0000
@@ -17,6 +17,7 @@
 
 #include "virterror_internal.h"
 #include "datatypes.h"
+#include "logging.h"
 
 virError virLastErr =       /* the last error */
   { .code = 0, .domain = 0, .message = NULL, .level = VIR_ERR_NONE,
@@ -62,6 +63,97 @@
     }}								\
 }
 
+static virLogPriority virErrorLevelPriority(virErrorLevel level) {
+    switch (level) {
+        case VIR_ERR_NONE:
+            return(VIR_LOG_INFO);
+        case VIR_ERR_WARNING:
+            return(VIR_LOG_WARN);
+        case VIR_ERR_ERROR:
+            return(VIR_LOG_ERROR);
+    }
+    return(VIR_LOG_ERROR);
+}
+
+static const char *virErrorDomainName(virErrorDomain domain) {
+    const char *dom = "unknown";
+    switch (domain) {
+        case VIR_FROM_NONE:
+            dom = "";
+            break;
+        case VIR_FROM_XEN:
+            dom = "Xen ";
+            break;
+        case VIR_FROM_XML:
+            dom = "XML ";
+            break;
+        case VIR_FROM_XEND:
+            dom = "Xen Daemon ";
+            break;
+        case VIR_FROM_XENSTORE:
+            dom = "Xen Store ";
+            break;
+        case VIR_FROM_XEN_INOTIFY:
+            dom = "Xen Inotify ";
+            break;
+        case VIR_FROM_DOM:
+            dom = "Domain ";
+            break;
+        case VIR_FROM_RPC:
+            dom = "XML-RPC ";
+            break;
+        case VIR_FROM_QEMU:
+            dom = "QEMU ";
+            break;
+        case VIR_FROM_NET:
+            dom = "Network ";
+            break;
+        case VIR_FROM_TEST:
+            dom = "Test ";
+            break;
+        case VIR_FROM_REMOTE:
+            dom = "Remote ";
+            break;
+        case VIR_FROM_SEXPR:
+            dom = "S-Expr ";
+            break;
+        case VIR_FROM_PROXY:
+            dom = "PROXY ";
+            break;
+        case VIR_FROM_CONF:
+            dom = "Config ";
+            break;
+        case VIR_FROM_OPENVZ:
+            dom = "OpenVZ ";
+            break;
+        case VIR_FROM_XENXM:
+            dom = "Xen XM ";
+            break;
+        case VIR_FROM_STATS_LINUX:
+            dom = "Linux Stats ";
+            break;
+        case VIR_FROM_LXC:
+            dom = "Linux Container ";
+            break;
+        case VIR_FROM_STORAGE:
+            dom = "Storage ";
+            break;
+        case VIR_FROM_NETWORK:
+            dom = "Network Config ";
+            break;
+        case VIR_FROM_DOMAIN:
+            dom = "Domain Config ";
+            break;
+        case VIR_FROM_NODEDEV:
+            dom = "Node Device ";
+            break;
+        case VIR_FROM_UML:
+            dom = "UML ";
+            break;
+    }
+    return(dom);
+}
+
 /*
  * virGetLastError:
  *
@@ -246,80 +338,7 @@
             lvl = _("error");
             break;
     }
-    switch (err->domain) {
-        case VIR_FROM_NONE:
-            dom = "";
-            break;
-        case VIR_FROM_XEN:
-            dom = "Xen ";
-            break;
-        case VIR_FROM_XML:
-            dom = "XML ";
-            break;
-        case VIR_FROM_XEND:
-            dom = "Xen Daemon ";
-            break;
-        case VIR_FROM_XENSTORE:
-            dom = "Xen Store ";
-            break;
-        case VIR_FROM_XEN_INOTIFY:
-            dom = "Xen Inotify ";
-            break;
-        case VIR_FROM_DOM:
-            dom = "Domain ";
-            break;
-        case VIR_FROM_RPC:
-            dom = "XML-RPC ";
-            break;
-        case VIR_FROM_QEMU:
-            dom = "QEMU ";
-            break;
-        case VIR_FROM_NET:
-            dom = "Network ";
-            break;
-        case VIR_FROM_TEST:
-            dom = "Test ";
-            break;
-        case VIR_FROM_REMOTE:
-            dom = "Remote ";
-            break;
-        case VIR_FROM_SEXPR:
-            dom = "S-Expr ";
-            break;
-        case VIR_FROM_PROXY:
-            dom = "PROXY ";
-            break;
-        case VIR_FROM_CONF:
-            dom = "Config ";
-            break;
-        case VIR_FROM_OPENVZ:
-            dom = "OpenVZ ";
-            break;
-        case VIR_FROM_XENXM:
-            dom = "Xen XM ";
-            break;
-        case VIR_FROM_STATS_LINUX:
-            dom = "Linux Stats ";
-            break;
-        case VIR_FROM_LXC:
-            dom = "Linux Container ";
-            break;
-        case VIR_FROM_STORAGE:
-            dom = "Storage ";
-            break;
-        case VIR_FROM_NETWORK:
-            dom = "Network Config ";
-            break;
-        case VIR_FROM_DOMAIN:
-            dom = "Domain Config ";
-            break;
-        case VIR_FROM_NODEDEV:
-            dom = "Node Device ";
-            break;
-        case VIR_FROM_UML:
-            dom = "UML ";
-            break;
-    }
+    dom = virErrorDomainName(err->domain);
     if ((err->dom != NULL) && (err->code != VIR_ERR_INVALID_DOMAIN)) {
         domain = err->dom->name;
     } else if ((err->net != NULL) && (err->code != VIR_ERR_INVALID_NETWORK)) {
@@ -392,6 +411,12 @@
     }
 
     /*
+     * Hook up the error or warning to the logging facility
+     */
+    virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level),
+                  1, "%s", str);
+
+    /*
      * Save the information about the error
      */
     virResetError(to);
--
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]