On 02.05.2012 13:44, Daniel P. Berrange wrote: > From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> > > 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 > --- > src/util/logging.c | 29 ++++++++++++++++++++++++----- > src/util/logging.h | 5 +++++ > 2 files changed, 29 insertions(+), 5 deletions(-) > > diff --git a/src/util/logging.c b/src/util/logging.c > index 48a056d..0007226 100644 > --- a/src/util/logging.c > +++ b/src/util/logging.c > @@ -683,6 +683,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); > +} > + > +/** > + * virLogMessage: > + * @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; > char *msg = NULL; > @@ -690,7 +713,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; > > if (!virLogInitialized) > virLogStartup(); > @@ -715,12 +737,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); > diff --git a/src/util/logging.h b/src/util/logging.h > index 2343de0..e1a8116 100644 > --- a/src/util/logging.h > +++ b/src/util/logging.h > @@ -128,6 +128,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 ACK Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list