On 08/18/2016 07:47 AM, Erik Skultety wrote:
This method will eventually replace virLogParseAndDefineFilters
which
currently does both parsing and defining.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virlog.c | 31 +++++++++++++++++++++++++++++++
src/util/virlog.h | 1 +
3 files changed, 33 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5fb30e6..fec0b8b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1875,6 +1875,7 @@ virLogPriorityFromSyslog;
virLogProbablyLogMessage;
virLogReset;
virLogSetDefaultPriority;
+virLogSetFilters;
virLogSetFromEnv;
virLogSetOutputs;
virLogUnlock;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index a60c027..b1d2543 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -2141,3 +2141,34 @@ virLogSetOutputs(const char *src)
virLogOutputListFree(outputs, noutputs);
return ret;
}
+
+
+/**
+ * virLogSetFilters:
+ * @src: string defining a (set of) filter(s)
+ *
+ * Replaces the current set of defined filters with a new set of filters.
+ *
+ * Returns the number of filters successfully defined or -1 in case of an
+ * error.
+ */
+int
+virLogSetFilters(const char *src)
+{
+ int ret = -1;
+ int nfilters = 0;
+ virLogFilterPtr *filters = NULL;
+
+ if (virLogInitialize() < 0)
+ return -1;
+
+ if ((nfilters = virLogParseFilters(src, &filters)) < 0)
+ goto cleanup;
+
+ if ((ret = virLogDefineFilters(filters, nfilters)) < 0)
+ goto cleanup;
+
Here you need the 'filters = NULL;', so the following doesn't undo what
you just did.
+ cleanup:
+ virLogFilterListFree(filters, nfilters);
+ return ret;
+}
diff --git a/src/util/virlog.h b/src/util/virlog.h
index 88e6ac8..2f88f2f 100644
--- a/src/util/virlog.h
+++ b/src/util/virlog.h
@@ -198,6 +198,7 @@ void virLogOutputListFree(virLogOutputPtr *list, int count);
void virLogFilterFree(virLogFilterPtr filter);
void virLogFilterListFree(virLogFilterPtr *list, int count);
int virLogSetOutputs(const char *outputs);
+int virLogSetFilters(const char *filters);
s/;/ATTRIBUTE_NONNULL(1);
ACK w/ adjustments
John
/*
* Internal logging API