提交 b0f5dc91 编写于 作者: E Erik Skultety

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: NErik Skultety <eskultet@redhat.com>
上级 a2405a88
......@@ -1882,6 +1882,7 @@ virLogLock;
virLogMessage;
virLogOutputFree;
virLogOutputListFree;
virLogOutputNew;
virLogParseAndDefineFilters;
virLogParseAndDefineOutputs;
virLogParseDefaultPriority;
......
......@@ -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;
}
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册