From 10a6a28ea8d8d931b6c7c57e85c15c9b7fbe5f5d Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Wed, 14 Sep 2011 22:44:32 +0200 Subject: [PATCH] logmsg: extend oldmg string buffer to 20 entries to avoid logging repeated obsoleted by msgs --- src/functions.c | 51 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/functions.c b/src/functions.c index abec004..ce84b84 100644 --- a/src/functions.c +++ b/src/functions.c @@ -121,34 +121,41 @@ void log_debug_set(int value) { void logmsg(int level, const char *msg, ...) { va_list ap; - static char oldmsg[1024] = ""; + static char oldmsg[20][256]; + static int curroldmsg = 0; char newmsg[1024]; + int i; va_start(ap, msg); vsnprintf((char*)&newmsg, 1024, msg, ap); va_end(ap); - if (strncmp(newmsg,(char*)&oldmsg,1024) != 0) /* only log the same message once */ - { - switch (level) { - case LOG_MARK: - fprintf(stderr,"Info: ******************************\n"); - fprintf(stderr,"Info: %s\n",(char*)&newmsg); - fprintf(stderr,"Info: ******************************\n"); - break; - case LOG_WARNING: - fprintf(stderr,"Warning: %s\n",(char*)&newmsg); - break; - case LOG_ERROR: - fprintf(stderr,"Error: %s\n",(char*)&newmsg); - break; - case LOG_DEBUG: - if (debug_log == 1) fprintf(stderr,"DEBUG: %s\n",(char*)&newmsg); - break; - default: - break; - } - strncpy(oldmsg,newmsg,1024); + for (i = 0; i < 20; i++) { + /* only log the same message once */ + if (!strncmp(newmsg,(char*)&(oldmsg[i]),256)) return; + } + + switch (level) { + case LOG_MARK: + fprintf(stderr,"Info: ******************************\n"); + fprintf(stderr,"Info: %s\n",(char*)&newmsg); + fprintf(stderr,"Info: ******************************\n"); + break; + case LOG_WARNING: + fprintf(stderr,"Warning: %s\n",(char*)&newmsg); + break; + case LOG_ERROR: + fprintf(stderr,"Error: %s\n",(char*)&newmsg); + break; + case LOG_DEBUG: + if (debug_log == 1) fprintf(stderr,"DEBUG: %s\n",(char*)&newmsg); + break; + default: + break; + } + if ((level == LOG_WARNING) || (level == LOG_ERROR)) { + strncpy(oldmsg[curroldmsg++],newmsg,256); + if (curroldmsg >= 20) curroldmsg = 0; } }