提交 e7df360d 编写于 作者: D Daniel P. Berrange

Add a virLogMessage alternative taking va_list args

Allow the logging APIs to be called with a va_list for format
args, instead of requiring var-args usage.

* src/util/logging.h, src/util/logging.c: Add virLogVMessage
上级 3337ba6d
......@@ -691,6 +691,29 @@ virLogVersionString(char **msg)
*/
void virLogMessage(const char *category, int priority, const char *funcname,
long long linenr, unsigned int flags, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
virLogVMessage(category, priority, funcname, linenr, flags, fmt, ap);
va_end(ap);
}
/**
* virLogVMessage:
* @category: where is that message coming from
* @priority: the priority level
* @funcname: the function emitting the (debug) message
* @linenr: line where the message was emitted
* @flags: extra flags, 1 if coming from the error handler
* @fmt: the string format
* @vargs: format args
*
* Call the libvirt logger with some information. Based on the configuration
* the message may be stored, sent to output or just discarded
*/
void virLogVMessage(const char *category, int priority, const char *funcname,
long long linenr, unsigned int flags, const char *fmt,
va_list vargs)
{
static bool logVersionStderr = true;
char *str = NULL;
......@@ -699,7 +722,6 @@ void virLogMessage(const char *category, int priority, const char *funcname,
int fprio, i, ret;
int saved_errno = errno;
int emit = 1;
va_list ap;
unsigned int filterflags = 0;
if (!virLogInitialized)
......@@ -725,12 +747,9 @@ void virLogMessage(const char *category, int priority, const char *funcname,
/*
* serialize the error message, add level and timestamp
*/
va_start(ap, fmt);
if (virVasprintf(&str, fmt, ap) < 0) {
va_end(ap);
if (virVasprintf(&str, fmt, vargs) < 0) {
goto cleanup;
}
va_end(ap);
ret = virLogFormatString(&msg, funcname, linenr, priority, str);
VIR_FREE(str);
......
......@@ -135,6 +135,11 @@ extern void virLogMessage(const char *category, int priority,
const char *funcname, long long linenr,
unsigned int flags,
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
extern void virLogVMessage(const char *category, int priority,
const char *funcname, long long linenr,
unsigned int flags,
const char *fmt,
va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);
extern int virLogSetBufferSize(int size);
extern void virLogEmergencyDumpAll(int signum);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册