[PATCH 2/5] virlog: Introduce Type{To, From}String for virLogDestination

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

 



In order to refactor the ugly virLogParseOutputs method, this is a neat way of
finding out whether the destination type (in the form of a string) user
provided is a valid one. As a bonus, if it turns out it is valid, we get the
actual enum which will later be passed to any of virLogAddOutput methods right
away.
---
 src/util/virlog.c | 25 +++++--------------------
 src/util/virlog.h |  5 ++++-
 2 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index b4c16de..b717947 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -43,7 +43,6 @@
 #include "virerror.h"
 #include "virlog.h"
 #include "viralloc.h"
-#include "virutil.h"
 #include "virbuffer.h"
 #include "virthread.h"
 #include "virfile.h"
@@ -73,6 +72,9 @@ static regex_t *virLogRegex;
     VIR_LOG_DATE_REGEX " " VIR_LOG_TIME_REGEX ": " \
     VIR_LOG_PID_REGEX ": " VIR_LOG_LEVEL_REGEX " : "
 
+VIR_ENUM_IMPL(virLogDestination, VIR_LOG_TO_OUTPUT_LAST,
+              "stderr", "syslog", "file", "journald");
+
 /*
  * Filters are used to refine the rules on what to keep or drop
  * based on a matching pattern (currently a substring)
@@ -148,23 +150,6 @@ virLogUnlock(void)
 
 
 static const char *
-virLogOutputString(virLogDestination ldest)
-{
-    switch (ldest) {
-    case VIR_LOG_TO_STDERR:
-        return "stderr";
-    case VIR_LOG_TO_SYSLOG:
-        return "syslog";
-    case VIR_LOG_TO_FILE:
-        return "file";
-    case VIR_LOG_TO_JOURNALD:
-        return "journald";
-    }
-    return "unknown";
-}
-
-
-static const char *
 virLogPriorityString(virLogPriority lvl)
 {
     switch (lvl) {
@@ -1340,13 +1325,13 @@ virLogGetOutputs(void)
             case VIR_LOG_TO_FILE:
                 virBufferAsprintf(&outputbuf, "%d:%s:%s",
                                   virLogOutputs[i].priority,
-                                  virLogOutputString(dest),
+                                  virLogDestinationTypeToString(dest),
                                   virLogOutputs[i].name);
                 break;
             default:
                 virBufferAsprintf(&outputbuf, "%d:%s",
                                   virLogOutputs[i].priority,
-                                  virLogOutputString(dest));
+                                  virLogDestinationTypeToString(dest));
         }
     }
     virLogUnlock();
diff --git a/src/util/virlog.h b/src/util/virlog.h
index 9ece3b5..f4e7b62 100644
--- a/src/util/virlog.h
+++ b/src/util/virlog.h
@@ -24,6 +24,7 @@
 
 # include "internal.h"
 # include "virbuffer.h"
+# include "virutil.h"
 
 # ifdef PACKAGER_VERSION
 #  ifdef PACKAGER
@@ -51,13 +52,15 @@ typedef enum {
 # define VIR_LOG_DEFAULT VIR_LOG_WARN
 
 typedef enum {
-    VIR_LOG_TO_STDERR = 1,
+    VIR_LOG_TO_STDERR = 0,
     VIR_LOG_TO_SYSLOG,
     VIR_LOG_TO_FILE,
     VIR_LOG_TO_JOURNALD,
     VIR_LOG_TO_OUTPUT_LAST,
 } virLogDestinationType;
 
+VIR_ENUM_DECL(virLogDestination)
+
 typedef struct _virLogSource virLogSource;
 typedef virLogSource *virLogSourcePtr;
 
-- 
2.4.3

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