]> xenbits.xensource.com Git - libvirt.git/commitdiff
convert old logging to the new API
authorDaniel Veillard <veillard@redhat.com>
Mon, 22 Dec 2008 10:48:59 +0000 (10:48 +0000)
committerDaniel Veillard <veillard@redhat.com>
Mon, 22 Dec 2008 10:48:59 +0000 (10:48 +0000)
* src/node_device_devkit.c src/uml_driver.c src/virterror.c:
  convert old logging to the new API
daniel

ChangeLog
src/node_device_devkit.c
src/uml_driver.c
src/virterror.c

index 55ecb2a42eab6f38221802f39e2974a1181c8ace..1a364f4a5314135dacc6e1539de962208fb95d02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Dec 22 11:47:44 CET 2008 Daniel Veillard <veillard@redhat.com>
+
+       * src/node_device_devkit.c src/uml_driver.c src/virterror.c:
+         convert old logging to the new API
+
 Mon Dec 22 11:45:07 CET 2008 Daniel Veillard <veillard@redhat.com>
 
        * src/libvirt.c: convert entry points to new logging
index 92b730c4fe793be2ce71415a9ed41f50150cf4c0..199143c3f8a8f008d2830f347314db3f81e0f580 100644 (file)
@@ -41,9 +41,6 @@
 
 static virDeviceMonitorStatePtr driverState;
 
-#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
-#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
-
 #define CONN_DRV_STATE(conn) \
         ((virDeviceMonitorStatePtr)((conn)->devMonPrivateData))
 #define DRV_STATE_DKCLIENT(ds) ((DevkitClient *)((ds)->privateData))
index 0a59a2f08576667870d44b93cbc5f4687099b898..ea718005bd752e02ef657c111c3da76c0eb9bf17 100644 (file)
 #include "uuid.h"
 #include "domain_conf.h"
 #include "datatypes.h"
+#include "logging.h"
 
 /* For storing short-lived temporary files. */
 #define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
 
 static int umlShutdown(void);
 
-/* umlDebug statements should be changed to use this macro instead. */
-#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
-#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
-
-#define umlLog(level, msg...) fprintf(stderr, msg)
+#define umlLog(level, msg, ...)                                     \
+    virLogMessage(__FILE__, level, __func__, __LINE__, 0, msg, __VA_ARGS__)
 
 static void umlDriverLock(struct uml_driver *driver)
 {
@@ -100,7 +98,7 @@ static int umlSetCloseExec(int fd) {
         goto error;
     return 0;
  error:
-    umlLog(UML_ERR,
+    umlLog(VIR_LOG_ERROR,
              "%s", _("Failed to set close-on-exec file descriptor flag\n"));
     return -1;
 }
@@ -141,7 +139,7 @@ umlAutostartConfigs(struct uml_driver *driver) {
             !virDomainIsActive(driver->domains.objs[i]) &&
             umlStartVMDaemon(conn, driver, driver->domains.objs[i]) < 0) {
             virErrorPtr err = virGetLastError();
-            umlLog(UML_ERR, _("Failed to autostart VM '%s': %s\n"),
+            umlLog(VIR_LOG_ERROR, _("Failed to autostart VM '%s': %s\n"),
                      driver->domains.objs[i]->def->name, err->message);
         }
     }
@@ -323,7 +321,7 @@ umlStartup(void) {
     uml_driver->nextvmid = 1;
 
     if (!(pw = getpwuid(uid))) {
-        umlLog(UML_ERR, _("Failed to find user record for uid '%d': %s\n"),
+        umlLog(VIR_LOG_ERROR, _("Failed to find user record for uid '%d': %s\n"),
                uid, strerror(errno));
         goto error;
     }
@@ -368,12 +366,12 @@ umlStartup(void) {
 
 
     if ((uml_driver->inotifyFD = inotify_init()) < 0) {
-        umlLog(UML_ERR, "%s", _("cannot initialize inotify"));
+        umlLog(VIR_LOG_ERROR, "%s", _("cannot initialize inotify"));
         goto error;
     }
 
     if (virFileMakePath(uml_driver->monitorDir) < 0) {
-        umlLog(UML_ERR, _("Failed to create monitor directory %s: %s"),
+        umlLog(VIR_LOG_ERROR, _("Failed to create monitor directory %s: %s"),
                uml_driver->monitorDir, strerror(errno));
         goto error;
     }
@@ -403,7 +401,7 @@ umlStartup(void) {
     return 0;
 
 out_of_memory:
-    umlLog (UML_ERR,
+    umlLog (VIR_LOG_ERROR,
               "%s", _("umlStartup: out of memory\n"));
 
 error:
@@ -785,25 +783,25 @@ static int umlStartVMDaemon(virConnectPtr conn,
     tmp = progenv;
     while (*tmp) {
         if (safewrite(logfd, *tmp, strlen(*tmp)) < 0)
-            umlLog(UML_WARN, _("Unable to write envv to logfile %d: %s\n"),
+            umlLog(VIR_LOG_WARN, _("Unable to write envv to logfile %d: %s\n"),
                    errno, strerror(errno));
         if (safewrite(logfd, " ", 1) < 0)
-            umlLog(UML_WARN, _("Unable to write envv to logfile %d: %s\n"),
+            umlLog(VIR_LOG_WARN, _("Unable to write envv to logfile %d: %s\n"),
                    errno, strerror(errno));
         tmp++;
     }
     tmp = argv;
     while (*tmp) {
         if (safewrite(logfd, *tmp, strlen(*tmp)) < 0)
-            umlLog(UML_WARN, _("Unable to write argv to logfile %d: %s\n"),
+            umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile %d: %s\n"),
                    errno, strerror(errno));
         if (safewrite(logfd, " ", 1) < 0)
-            umlLog(UML_WARN, _("Unable to write argv to logfile %d: %s\n"),
+            umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile %d: %s\n"),
                    errno, strerror(errno));
         tmp++;
     }
     if (safewrite(logfd, "\n", 1) < 0)
-        umlLog(UML_WARN, _("Unable to write argv to logfile %d: %s\n"),
+        umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile %d: %s\n"),
                  errno, strerror(errno));
 
     vm->monitor = -1;
@@ -820,7 +818,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
 
     /* Cleanup intermediate proces */
     if (waitpid(pid, NULL, 0) != pid)
-        umlLog(UML_WARN, _("failed to wait on process: %d: %s\n"),
+        umlLog(VIR_LOG_WARN, _("failed to wait on process: %d: %s\n"),
                pid, strerror(errno));
 
     for (i = 0 ; argv[i] ; i++)
@@ -861,7 +859,7 @@ static void umlShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
     vm->monitor = -1;
 
     if ((ret = waitpid(vm->pid, NULL, 0)) != vm->pid) {
-        umlLog(UML_WARN,
+        umlLog(VIR_LOG_WARN,
                _("Got unexpected pid %d != %d\n"),
                ret, vm->pid);
     }
index 5a0b827031fd220924d5af4280c11789321ae9bc..5f9fb4150fef59cc0782d2794f23b3dc91dcc86f 100644 (file)
@@ -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 @@ void *virUserData = NULL;        /* associated data */
     }}                                                         \
 }
 
+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 @@ virDefaultErrorFunc(virErrorPtr err)
             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)) {
@@ -391,6 +410,13 @@ virRaiseError(virConnectPtr conn, virDomainPtr dom, virNetworkPtr net,
         VIR_GET_VAR_STR(msg, str);
     }
 
+    /*
+     * Hook up the error or warning to the logging facility
+     * TODO: pass function name and lineno
+     */
+    virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level),
+                  NULL, 0, 1, "%s", str);
+
     /*
      * Save the information about the error
      */