]> xenbits.xensource.com Git - libvirt.git/commitdiff
virlog: Introduce virLogOutputNew
authorErik Skultety <eskultet@redhat.com>
Fri, 8 Jul 2016 11:46:36 +0000 (13:46 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 10 Oct 2016 06:27:24 +0000 (08:27 +0200)
In order to later split output parsing and output defining, introduce a new
function which will create a new virLogOutput object which the parser will
insert into a list with the list being eventually defined.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/libvirt_private.syms
src/util/virlog.c
src/util/virlog.h

index a449e5fb64438a4f1ec02a3a71b7e1e3181e84f5..04adf6c0af3bc6d13567c5ad952ec6070cd3a6af 100644 (file)
@@ -1882,6 +1882,7 @@ virLogLock;
 virLogMessage;
 virLogOutputFree;
 virLogOutputListFree;
+virLogOutputNew;
 virLogParseAndDefineFilters;
 virLogParseAndDefineOutputs;
 virLogParseDefaultPriority;
index 85a21f08d799cd8b51a348746ebe9d9b03f1da5a..9764f1c1f0226416ddafc0b41817b3d310d2a291 100644 (file)
@@ -1546,3 +1546,58 @@ bool virLogProbablyLogMessage(const char *str)
         ret = true;
     return ret;
 }
+
+
+/**
+ * virLogOutputNew:
+ * @f: the function to call to output a message
+ * @c: the function to call to close the output (or NULL)
+ * @data: extra data passed as first arg to functions @f and @c
+ * @priority: minimal priority for this filter, use 0 for none
+ * @dest: where to send output of this priority (see virLogDestination)
+ * @name: additional data associated with syslog and file-based outputs (ident
+ *        and filename respectively)
+ *
+ * Allocates and returns a new log output object. The object has to be later
+ * defined, so that the output will be taken into account when emitting a
+ * message.
+ *
+ * Returns reference to a newly created object or NULL in case of failure.
+ */
+virLogOutputPtr
+virLogOutputNew(virLogOutputFunc f,
+                virLogCloseFunc c,
+                void *data,
+                virLogPriority priority,
+                virLogDestination dest,
+                const char *name)
+{
+    virLogOutputPtr ret = NULL;
+    char *ndup = NULL;
+
+    if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) {
+        if (!name) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("Missing auxiliary data in output definition"));
+            return NULL;
+        }
+
+        if (VIR_STRDUP(ndup, name) < 0)
+            return NULL;
+    }
+
+    if (VIR_ALLOC(ret) < 0) {
+        VIR_FREE(ndup);
+        return NULL;
+    }
+
+    ret->logInitMessage = true;
+    ret->f = f;
+    ret->c = c;
+    ret->data = data;
+    ret->priority = priority;
+    ret->dest = dest;
+    ret->name = ndup;
+
+    return ret;
+}
index de64f4c48c7938c48378d84c5270735e4bd3921e..75bc5ba65abe7bf21b019dfc722f21c6dfc8911c 100644 (file)
@@ -226,5 +226,11 @@ void virLogVMessage(virLogSourcePtr source,
                     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) ATTRIBUTE_NONNULL(1);
 
 #endif