Continuing with the refactor, in order to later split output parsing and output defining, introduce a new function which will create a new virLogOutput object which parser will insert into a list with the list being eventually defined. Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/util/virlog.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++- src/util/virlog.h | 6 ++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 35200a3..b5cee5f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1854,6 +1854,7 @@ virLogLock; virLogMessage; virLogOutputFree; virLogOutputListFree; +virLogOutputNew; virLogParseAndDefineFilters; virLogParseAndDefineOutputs; virLogParseDefaultPriority; diff --git a/src/util/virlog.c b/src/util/virlog.c index 3ada288..91c63a1 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -366,7 +366,6 @@ virLogOutputFree(virLogOutputPtr output) output->c(output->data); VIR_FREE(output->name); VIR_FREE(output); - } @@ -1551,3 +1550,57 @@ 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 the function + * @priority: minimal priority for this filter, use 0 for none + * @dest: where to send output of this priority (see virLogDestination) + * @name: optional name data associated with an output + * + * 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 (!f) + return NULL; + + if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) { + if (!name) + return NULL; + + if (VIR_STRDUP(ndup, name) < 0) + return NULL; + } + + if (VIR_ALLOC_QUIET(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; +} diff --git a/src/util/virlog.h b/src/util/virlog.h index de64f4c..fb32c41 100644 --- a/src/util/virlog.h +++ b/src/util/virlog.h @@ -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); #endif -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list