From ee4f2d22ab446d484de91f853293edb6e8801c77 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 9 Feb 2015 08:21:59 -0500 Subject: [PATCH] convert ilog() into macro --- daemon/log.c | 11 +---------- daemon/log.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/daemon/log.c b/daemon/log.c index 3eec0c1eb..6991f92b0 100644 --- a/daemon/log.c +++ b/daemon/log.c @@ -85,7 +85,7 @@ void log_to_stderr(int facility_priority, char *format, ...) { free(msg); } -void ilog(int prio, const char *fmt, ...) { +void __ilog(int prio, const char *fmt, ...) { char prefix[256]; char *msg, *piece; const char *infix = ""; @@ -94,15 +94,6 @@ void ilog(int prio, const char *fmt, ...) { xprio = LOG_LEVEL_MASK(prio); -#ifndef __DEBUG - int level; /* thank you C99 */ - level = get_log_level(); - if (xprio > LOG_LEVEL_MASK(level)) - return; - if ((level & LOG_FLAG_RESTORE) && !(prio & LOG_FLAG_RESTORE)) - return; -#endif - switch (log_info.e) { case LOG_INFO_NONE: prefix[0] = 0; diff --git a/daemon/log.h b/daemon/log.h index c68a87177..73d49ec23 100644 --- a/daemon/log.h +++ b/daemon/log.h @@ -45,7 +45,20 @@ extern unsigned int max_log_line_length; void log_init(void); -void ilog(int prio, const char *fmt, ...)__attribute__ ((format (printf, 2, 3))); +void __ilog(int prio, const char *fmt, ...)__attribute__ ((format (printf, 2, 3))); +#ifndef __DEBUG +#define ilog(prio, fmt...) \ + do { \ + int loglevel = get_log_level(); \ + if (LOG_LEVEL_MASK((prio)) > LOG_LEVEL_MASK(loglevel)) \ + break; \ + if ((loglevel & LOG_FLAG_RESTORE) && !((prio) & LOG_FLAG_RESTORE)) \ + break; \ + __ilog(prio, fmt); \ + } while (0) +#else +#define ilog(prio, fmt...) __ilog(prio, fmt) +#endif void cdrlog(const char* cdrbuffer);