]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Several fixes to libvirtd's log setup
authorAmy Griffis <amy.griffis@hp.com>
Thu, 6 Aug 2009 13:45:50 +0000 (15:45 +0200)
committerDaniel Veillard <veillard@redhat.com>
Thu, 6 Aug 2009 13:45:50 +0000 (15:45 +0200)
* qemud/qemud.c src/logging.[ch]: Similar as for general libvirt, don't
  convert high priority levels to debug level. Ignore LIBVIRT_LOG_FILTERS
  and LIBVIRT_LOG_OUTPUTS when they're set to the empty string, otherwise
  they can override a valid setting from the config file. Send all
  settings through the parser functions for validation, so that the
  existence of a bad setting doesn't nullify a good setting that should
  have applied -- particularly the default output. Keep the order of
  precedence consistent for all variables between the environment and
  the config file.  Warn when an invalid log level, filter, or output
  is ignored.
* src/libvirt_private.syms: export internally a few convenience functions

qemud/qemud.c
src/libvirt_private.syms
src/logging.c
src/logging.h

index 3e551ca17da87da9c075b8bb9460253bd58b8e07..0b0883b149b1357ec4cf3d94a2e853f6d6a4435f 100644 (file)
@@ -132,11 +132,6 @@ static int timeout = -1;        /* -t: Shutdown timeout */
 static int sigwrite = -1;       /* Signal handler pipe */
 static int ipsock = 0;          /* -l  Listen for TCP/IP */
 
-/* Defaults for logging */
-static int log_level = VIR_LOG_DEFAULT;
-static char *log_filters = NULL;
-static char *log_outputs = NULL;
-
 /* Defaults for configuration file elements */
 static int listen_tls = 1;
 static int listen_tcp = 0;
@@ -2494,6 +2489,9 @@ remoteReadSaslAllowedUsernameList (virConfPtr conf ATTRIBUTE_UNUSED,
 static int
 qemudSetLogging(virConfPtr conf, const char *filename) {
     char *debugEnv;
+    int log_level;
+    char *log_filters = NULL;
+    char *log_outputs = NULL;
     int ret = -1;
 
     virLogReset();
@@ -2503,54 +2501,70 @@ qemudSetLogging(virConfPtr conf, const char *filename) {
      * then from environment variable and finally from command
      * line options
      */
+    /*
+     * GET_CONF_INT returns 0 when there is no log_level setting in
+     * the config file. The conditional below eliminates a false
+     * warning in that case, but also has the side effect of missing
+     * a warning if the user actually does say log_level=0.
+     */
     GET_CONF_INT (conf, filename, log_level);
+    if (log_level != 0)
+        virLogSetDefaultPriority(log_level);
+
     debugEnv = getenv("LIBVIRT_DEBUG");
-    if (debugEnv && *debugEnv && *debugEnv != '0') {
-        if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
-            log_level = VIR_LOG_INFO;
+    if (debugEnv && *debugEnv) {
+        if (STREQ(debugEnv, "1") || STREQ(debugEnv, "debug"))
+            virLogSetDefaultPriority(VIR_LOG_DEBUG);
+        else if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
+            virLogSetDefaultPriority(VIR_LOG_INFO);
         else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning"))
-            log_level = VIR_LOG_WARN;
+            virLogSetDefaultPriority(VIR_LOG_WARN);
         else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error"))
-            log_level = VIR_LOG_ERROR;
+            virLogSetDefaultPriority(VIR_LOG_ERROR);
         else
-            log_level = VIR_LOG_DEBUG;
+            VIR_WARN0(_("Ignoring invalid log level setting."));
+    }
+
+    if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO))
+        virLogSetDefaultPriority(VIR_LOG_INFO);
+
+    debugEnv = getenv("LIBVIRT_LOG_FILTERS");
+    if (debugEnv && *debugEnv)
+        virLogParseFilters(strdup(debugEnv));
+
+    if (virLogGetNbFilters() == 0) {
+        GET_CONF_STR (conf, filename, log_filters);
+        virLogParseFilters(log_filters);
     }
-    if ((verbose) && (log_level >= VIR_LOG_WARN))
-        log_level = VIR_LOG_INFO;
-    virLogSetDefaultPriority(log_level);
 
     /* there is no default filters */
-    GET_CONF_STR (conf, filename, log_filters);
-    if (!log_filters) {
-        debugEnv = getenv("LIBVIRT_LOG_FILTERS");
-        if (debugEnv)
-            log_filters = strdup(debugEnv);
+
+    debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
+    if (debugEnv && *debugEnv)
+        virLogParseOutputs(strdup(debugEnv));
+
+    if (virLogGetNbOutputs() == 0) {
+        GET_CONF_STR (conf, filename, log_outputs);
+        virLogParseOutputs(log_outputs);
     }
-    virLogParseFilters(log_filters);
 
     /*
-     * by default save all warning and errors to syslog or
-     * all logs to stderr if not running as daemon
+     * If no defined outputs, then direct to syslog when running
+     * as daemon. Otherwise the default output is stderr.
      */
-    GET_CONF_STR (conf, filename, log_outputs);
-    if (!log_outputs) {
-        debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
-        if (debugEnv)
-            log_outputs = strdup(debugEnv);
-    }
-    if (!log_outputs) {
+    if (virLogGetNbOutputs() == 0) {
         char *tmp = NULL;
         if (godaemon) {
-            if (virAsprintf (&tmp, "%d:syslog:libvirtd", log_level) < 0)
+            if (virAsprintf (&tmp, "%d:syslog:libvirtd",
+                             virLogGetDefaultPriority()) < 0)
                 goto free_and_fail;
         } else {
-            if (virAsprintf(&tmp, "%d:stderr", log_level) < 0)
+            if (virAsprintf (&tmp, "%d:stderr",
+                             virLogGetDefaultPriority()) < 0)
                 goto free_and_fail;
         }
         virLogParseOutputs(tmp);
         VIR_FREE(tmp);
-    } else {
-        virLogParseOutputs(log_outputs);
     }
     ret = 0;
 
index bd636928a4ea559d9b2653c6c1aae3d9715f2fc7..487585c9717e0ee7c6406073f548ca4fa6e86a30 100644 (file)
@@ -213,6 +213,9 @@ virRegisterDeviceMonitor;
 
 # logging.h
 virLogMessage;
+virLogGetNbFilters;
+virLogGetNbOutputs;
+virLogGetDefaultPriority;
 virLogSetDefaultPriority;
 virLogDefineFilter;
 virLogDefineOutput;
index 27d6e4bfb4d0e691b12186f00edd2fad3e98c9fa..aad4b50f31163ecc022d611a69a4f0a11bed2be0 100644 (file)
@@ -802,3 +802,30 @@ cleanup:
         VIR_WARN0(_("Ignoring invalid log filter setting."));
     return(ret);
 }
+
+/**
+ * virLogGetDefaultPriority:
+ *
+ * Returns the current logging priority level.
+ */
+int virLogGetDefaultPriority(void) {
+    return (virLogDefaultPriority);
+}
+
+/**
+ * virLogGetNbFilters:
+ *
+ * Returns the current number of defined log filters.
+ */
+int virLogGetNbFilters(void) {
+    return (virLogNbFilters);
+}
+
+/**
+ * virLogGetNbOutputs:
+ *
+ * Returns the current number of defined log outputs.
+ */
+int virLogGetNbOutputs(void) {
+    return (virLogNbOutputs);
+}
index f1e252598f94e3960f780346fc7473902b150a65..c8698e5254ff4c1fad19ccd7a4977a6473838fff 100644 (file)
@@ -105,6 +105,9 @@ typedef int (*virLogOutputFunc) (const char *category, int priority,
  */
 typedef void (*virLogCloseFunc) (void *data);
 
+extern int virLogGetNbFilters(void);
+extern int virLogGetNbOutputs(void);
+extern int virLogGetDefaultPriority(void);
 extern int virLogSetDefaultPriority(int priority);
 extern int virLogDefineFilter(const char *match, int priority, int flags);
 extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c,