mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
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
This commit is contained in:
parent
3337ba6dc7
commit
e7df360d56
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user