[PATCH v2 10/20] virlog: Introduce virLogParseFilter

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

 



Same as for outputs, introduce a new method, that is basically the same as
virLogParseAndDefineFilter with the difference that it does not define the
filter. It rather returns a newly created object that needs to be inserted into
a list and then defined separately.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virlog.c        | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/util/virlog.h        |  1 +
 3 files changed, 47 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 79a6adc..1dfd7c8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1867,6 +1867,7 @@ virLogOutputNew;
 virLogParseAndDefineFilters;
 virLogParseAndDefineOutputs;
 virLogParseDefaultPriority;
+virLogParseFilter;
 virLogParseOutput;
 virLogPriorityFromSyslog;
 virLogProbablyLogMessage;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 7a6e639..43b3d75 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1921,3 +1921,48 @@ virLogParseOutput(const char *src)
     virStringFreeList(tokens);
     return ret;
 }
+
+virLogFilterPtr
+virLogParseFilter(const char *filter)
+{
+    virLogFilterPtr ret = NULL;
+    size_t count = 0;
+    virLogPriority prio;
+    char **tokens = NULL;
+    unsigned int flags = 0;
+    char *ref = NULL;
+
+    if (!filter)
+        return NULL;
+
+    VIR_DEBUG("filter=%s", filter);
+
+    if (!(tokens = virStringSplitCount(filter, ":", 0, &count)))
+        return NULL;
+
+    if (count != 2)
+        goto cleanup;
+
+    if (virStrToLong_uip(tokens[0], NULL, 10, &prio) < 0 ||
+        (prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
+        goto cleanup;
+
+    ref = tokens[1];
+    if (ref[0] == '+') {
+        flags |= VIR_LOG_STACK_TRACE;
+        ref++;
+    }
+
+    if (!*ref)
+        goto cleanup;
+
+    if (!(ret = virLogFilterNew(ref, prio, flags)))
+        goto cleanup;
+
+ cleanup:
+    if (!ret)
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to parse and define log filter %s"), filter);
+    virStringFreeList(tokens);
+    return ret;
+}
diff --git a/src/util/virlog.h b/src/util/virlog.h
index af26e30..e7f6b85 100644
--- a/src/util/virlog.h
+++ b/src/util/virlog.h
@@ -246,5 +246,6 @@ virLogOutputPtr virLogNewOutputToSyslog(virLogPriority priority,
                                         const char *ident);
 virLogOutputPtr virLogNewOutputToJournald(int priority);
 virLogOutputPtr virLogParseOutput(const char *src);
+virLogFilterPtr virLogParseFilter(const char *src);
 
 #endif
-- 
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]