]> xenbits.xensource.com Git - libvirt.git/commitdiff
virlog: Introduce Type{To,From}String for virLogDestination
authorErik Skultety <eskultet@redhat.com>
Tue, 15 Mar 2016 20:35:17 +0000 (21:35 +0100)
committerErik Skultety <eskultet@redhat.com>
Wed, 16 Mar 2016 13:24:15 +0000 (14:24 +0100)
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
src/util/virlog.h

index b8398d14f607b1606d4c552d3ad725f219ec2915..cfa44376f5b88e322ab6f713b3bc352d9b0ea5ed 100644 (file)
@@ -73,6 +73,10 @@ static regex_t *virLogRegex;
     VIR_LOG_DATE_REGEX " " VIR_LOG_TIME_REGEX ": " \
     VIR_LOG_PID_REGEX ": " VIR_LOG_LEVEL_REGEX " : "
 
+VIR_ENUM_DECL(virLogDestination);
+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)
@@ -147,23 +151,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)
 {
@@ -1340,13 +1327,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();
index 443b3cdda8413cb1121b81a1dc6477ca48d776b0..b5056f541e997c02edaf671d9fdb6a1934276486 100644 (file)
@@ -51,10 +51,11 @@ 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,
 } virLogDestination;
 
 typedef struct _virLogSource virLogSource;