From b0f5dc91476c0270992ea0c0536473a859b0b67d Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Fri, 8 Jul 2016 13:46:36 +0200 Subject: [PATCH] virlog: Introduce virLogOutputNew 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 --- src/libvirt_private.syms | 1 + src/util/virlog.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/virlog.h | 6 +++++ 3 files changed, 62 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a449e5fb64..04adf6c0af 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1882,6 +1882,7 @@ virLogLock; virLogMessage; virLogOutputFree; virLogOutputListFree; +virLogOutputNew; virLogParseAndDefineFilters; virLogParseAndDefineOutputs; virLogParseDefaultPriority; diff --git a/src/util/virlog.c b/src/util/virlog.c index 85a21f08d7..9764f1c1f0 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -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; +} diff --git a/src/util/virlog.h b/src/util/virlog.h index de64f4c48c..75bc5ba65a 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) ATTRIBUTE_NONNULL(1); #endif -- GitLab