[PATCH v2 20/20] virlog: Split parsing and setting priority

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

 



Handling of outputs and filters has been changed in a way that splits
parsing and defining. Do the same thing for logging priority as well, this
however, doesn't need much of a preparation.
---
 src/util/virlog.c | 21 +++++++++------------
 tests/eventtest.c |  3 ++-
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index 713cd0c..683cf6b 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -220,7 +220,9 @@ int
 virLogSetDefaultPriority(virLogPriority priority)
 {
     if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) {
-        VIR_WARN("Ignoring invalid log level setting.");
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Failed to set logging priority, argument '%u' is "
+                         "invalid"), priority);
         return -1;
     }
     if (virLogInitialize() < 0)
@@ -1158,20 +1160,15 @@ virLogGetNbOutputs(void)
 int
 virLogParseDefaultPriority(const char *priority)
 {
-    int ret = -1;
-
     if (STREQ(priority, "1") || STREQ(priority, "debug"))
-        ret = virLogSetDefaultPriority(VIR_LOG_DEBUG);
+        return VIR_LOG_DEBUG;
     else if (STREQ(priority, "2") || STREQ(priority, "info"))
-        ret = virLogSetDefaultPriority(VIR_LOG_INFO);
+        return VIR_LOG_INFO;
     else if (STREQ(priority, "3") || STREQ(priority, "warning"))
-        ret = virLogSetDefaultPriority(VIR_LOG_WARN);
+        return VIR_LOG_WARN;
     else if (STREQ(priority, "4") || STREQ(priority, "error"))
-        ret = virLogSetDefaultPriority(VIR_LOG_ERROR);
-    else
-        VIR_WARN("Ignoring invalid log level setting");
-
-    return ret;
+        return VIR_LOG_ERROR;
+    return -1;
 }
 
 
@@ -1191,7 +1188,7 @@ virLogSetFromEnv(void)
 
     debugEnv = virGetEnvAllowSUID("LIBVIRT_DEBUG");
     if (debugEnv && *debugEnv)
-        virLogParseDefaultPriority(debugEnv);
+        virLogSetDefaultPriority(virLogParseDefaultPriority(debugEnv));
     debugEnv = virGetEnvAllowSUID("LIBVIRT_LOG_FILTERS");
     if (debugEnv && *debugEnv)
         virLogSetFilters(debugEnv);
diff --git a/tests/eventtest.c b/tests/eventtest.c
index 4b62f34..011bedc 100644
--- a/tests/eventtest.c
+++ b/tests/eventtest.c
@@ -311,7 +311,8 @@ mymain(void)
     if (virThreadInitialize() < 0)
         return EXIT_FAILURE;
     char *debugEnv = getenv("LIBVIRT_DEBUG");
-    if (debugEnv && *debugEnv && (virLogParseDefaultPriority(debugEnv) == -1)) {
+    if (debugEnv && *debugEnv &&
+        (virLogSetDefaultPriority(virLogParseDefaultPriority(debugEnv)) < 0)) {
         fprintf(stderr, "Invalid log level setting.\n");
         return EXIT_FAILURE;
     }
-- 
2.5.5

--
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]