[PATCH v2 05/20] virlog: Introduce virLogDefineOutputs

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

 



Prepare a method that only defines a set of outputs. It takes a list of
outputs, preferably created by virLogParseOutputs. The original set of outputs
is reset and replaced by the new user-provided set of outputs.

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

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d28405c..fb7f277 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1844,6 +1844,7 @@ virLockSpaceReleaseResourcesForOwner;
 # util/virlog.h
 virLogDefineFilter;
 virLogDefineOutput;
+virLogDefineOutputs;
 virLogFilterFree;
 virLogFilterListFree;
 virLogFilterNew;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 5916ac8..2651f70 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1682,3 +1682,28 @@ virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
 
     return -1;
 }
+
+
+/**
+ * virLogDefineOutputs:
+ * @outputs: new set of outputs to be defined
+ * @noutputs: number of outputs in @outputs
+ *
+ * Resets any existing set of outputs and defines a completely new one.
+ *
+ * Returns number of outputs successfully defined or -1 in case of error;
+ */
+int
+virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
+{
+    if (virLogInitialize() < 0)
+        return -1;
+
+    virLogLock();
+    virLogResetOutputs();
+    virLogOutputs = outputs;
+    virLogNbOutputs = noutputs;
+    virLogUnlock();
+
+    return virLogNbOutputs;
+}
diff --git a/src/util/virlog.h b/src/util/virlog.h
index 2045c06..8568830 100644
--- a/src/util/virlog.h
+++ b/src/util/virlog.h
@@ -173,7 +173,7 @@ typedef void (*virLogOutputFunc) (virLogSourcePtr src,
 typedef void (*virLogCloseFunc) (void *data);
 
 typedef enum {
-    VIR_LOG_STACK_TRACE = (1 << 0),
+VIR_LOG_STACK_TRACE = (1 << 0),
 } virLogFlags;
 
 int virLogGetNbFilters(void);
@@ -184,23 +184,23 @@ virLogPriority virLogGetDefaultPriority(void);
 int virLogSetDefaultPriority(virLogPriority priority);
 void virLogSetFromEnv(void);
 int virLogDefineFilter(const char *match,
-                       virLogPriority priority,
-                       unsigned int flags);
+                   virLogPriority priority,
+                   unsigned int flags);
 int virLogDefineOutput(virLogOutputFunc f,
-                       virLogCloseFunc c,
-                       void *data,
-                       virLogPriority priority,
-                       virLogDestination dest,
-                       const char *name,
-                       unsigned int flags);
+                   virLogCloseFunc c,
+                   void *data,
+                   virLogPriority priority,
+                   virLogDestination dest,
+                   const char *name,
+                   unsigned int flags);
 void virLogOutputFree(virLogOutputPtr output);
 void virLogOutputListFree(virLogOutputPtr *list, int count);
 void virLogFilterFree(virLogFilterPtr filter);
 void virLogFilterListFree(virLogFilterPtr *list, int count);
 
 /*
- * Internal logging API
- */
+* Internal logging API
+*/
 
 void virLogLock(void);
 void virLogUnlock(void);
@@ -210,32 +210,33 @@ int virLogParseAndDefineFilters(const char *filters);
 int virLogParseAndDefineOutputs(const char *output);
 int virLogPriorityFromSyslog(int priority);
 void virLogMessage(virLogSourcePtr source,
-                   virLogPriority priority,
-                   const char *filename,
-                   int linenr,
-                   const char *funcname,
-                   virLogMetadataPtr metadata,
-                   const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(7, 8);
+               virLogPriority priority,
+               const char *filename,
+               int linenr,
+               const char *funcname,
+               virLogMetadataPtr metadata,
+               const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(7, 8);
 void virLogVMessage(virLogSourcePtr source,
-                    virLogPriority priority,
-                    const char *filename,
-                    int linenr,
-                    const char *funcname,
-                    virLogMetadataPtr metadata,
-                    const char *fmt,
-                    va_list vargs) ATTRIBUTE_FMT_PRINTF(7, 0);
+                virLogPriority priority,
+                const char *filename,
+                int linenr,
+                const char *funcname,
+                virLogMetadataPtr metadata,
+                const char *fmt,
+                va_list vargs) ATTRIBUTE_FMT_PRINTF(7, 0);
 
 bool virLogProbablyLogMessage(const char *str);
 virLogOutputPtr virLogOutputNew(virLogOutputFunc f,
-                                virLogCloseFunc c,
-                                void *data,
-                                virLogPriority priority,
-                                virLogDestination dest,
-                                const char *name);
+                            virLogCloseFunc c,
+                            void *data,
+                            virLogPriority priority,
+                            virLogDestination dest,
+                            const char *name);
 virLogFilterPtr virLogFilterNew(const char *match,
-                                virLogPriority priority,
-                                unsigned int flags);
+                            virLogPriority priority,
+                            unsigned int flags);
 int virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
                      virLogDestination dest, const void *opaque);
+int virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs);
 
 #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]