From 512731c9dcf9bb414f353e4a02e76fab965cc131 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Mon, 1 Jun 2009 16:01:47 +0200 Subject: [PATCH] Turn DPRINTF into a wrapper to a generic logging function DPRINTF() made a generic logging function taking a va_list called vlogger() and reimplemented as a wrapper on top of vlogger(). --- src/logger.c | 16 +++++++++++++--- src/logger.h | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/logger.c b/src/logger.c index d2b2d8d2..f90e7425 100644 --- a/src/logger.c +++ b/src/logger.c @@ -70,7 +70,7 @@ set_logdomains(char *domains) } void -DPRINTF(int severity, int domain, char *fmt, ...) +vlogger(int severity, int domain, char *fmt, va_list args) { va_list ap; char stamp[32]; @@ -97,7 +97,7 @@ DPRINTF(int severity, int domain, char *fmt, ...) fprintf(logfile, "[%s] %6s: ", stamp, labels[domain]); - va_start(ap, fmt); + va_copy(ap, args); vfprintf(logfile, fmt, ap); va_end(ap); } @@ -106,7 +106,7 @@ DPRINTF(int severity, int domain, char *fmt, ...) { fprintf(stderr, "%6s: ", labels[domain]); - va_start(ap, fmt); + va_copy(ap, args); vfprintf(stderr, fmt, ap); va_end(ap); } @@ -114,6 +114,16 @@ DPRINTF(int severity, int domain, char *fmt, ...) pthread_mutex_unlock(&logger_lck); } +void +DPRINTF(int severity, int domain, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vlogger(severity, domain, fmt, ap); + va_end(ap); +} + void logger_libevent(int severity, const char *msg) { diff --git a/src/logger.h b/src/logger.h index 319406bd..7221f262 100644 --- a/src/logger.h +++ b/src/logger.h @@ -2,6 +2,8 @@ #ifndef __LOGGER_H__ #define __LOGGER_H__ +#include + /* Log domains */ #define L_CONF 0 #define L_DAAP 1 @@ -30,6 +32,9 @@ #define E_SPAM 5 +void +vlogger(int severity, int domain, char *fmt, va_list args); + void DPRINTF(int severity, int domain, char *fmt, ...);