From 1f23c19e1c9f999a72655fe21531edbbe5e2f831 Mon Sep 17 00:00:00 2001 From: Koennecke Mark Date: Wed, 18 May 2016 11:33:59 +0200 Subject: [PATCH] Added a feature which allows suppression of certain log messages. For example TRANSACT messages --- logv2.c | 36 +++++++++++++++++++++++++++++++++--- logv2.h | 2 +- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/logv2.c b/logv2.c index 4cbdf83f..11096a28 100644 --- a/logv2.c +++ b/logv2.c @@ -32,6 +32,8 @@ static unsigned int globalLogLevel = INFO; /*========= The list of sub systems for which full logging is enabled ==========*/ unsigned int logEnabledArray[MAXSUB ]; +/*========== A list of entries to suppress =====================================*/ +int suppressList; /*================== Callback management =======================================*/ typedef struct { @@ -243,7 +245,7 @@ void formatSubsystem(unsigned int sub, char *buffer, unsigned int bufferLength) strncpy(buffer,subText[sub],bufferLength); } /*----------------------------------------------------------------------------*/ -unsigned int logFilter(unsigned int severity, const char *subsystem) +unsigned int logFilter(unsigned int severity, const char *subsystem, const char *logMessage) { int status; char buffer[1024]; @@ -253,6 +255,18 @@ unsigned int logFilter(unsigned int severity, const char *subsystem) return 1; } + /* + test if it is in the suppression list + */ + status = LLDnodePtr2First(suppressList); + while (status == 1) { + LLDstringData(suppressList, buffer); + if(strstr(logMessage,buffer) != NULL){ + return 1; + } + status = LLDnodePtr2Next(suppressList); + } + /* If it is in the list of enabled subsystems, everything is logged @@ -356,7 +370,7 @@ static void LogInternal(char *timeText, unsigned int severity, const char *subsy notifyListeners(severity,subsystem,timeText, logMessage); - if(logFilter(severity,subsystem) == 1){ + if(logFilter(severity,subsystem,(const char *)logMessage) == 1){ return; } @@ -655,6 +669,21 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics, SCWrite(pCon,GetCharArray(result),eValue); DeleteDynString(result); } + }else if (strcmp(argv[1],"suppress") == 0) { + if(argc > 2){ + /* + The 1024 is related to the size of the buffer in logFilter + */ + if(strlen(argv[2]) >= 1024) { + SCWrite(pCon,"ERROR: string to suppress to long",eError); + return 0; + } + LLDstringAppend(suppressList,argv[2]); + SCSendOK(pCon); + } else { + SCWrite(pCon,"ERROR: need text to suppress",eError); + return 0; + } } else { SCPrintf(pCon,eError,"ERROR: unknown keyword %s",argv[1]); return 0; @@ -672,7 +701,8 @@ void Logv2Init(void) { int i; - callbackList = LLDcreate(sizeof(LogCBData)); + callbackList = LLDcreate(sizeof(LogCBData)); + suppressList = LLDstringCreate(); strcpy(logTemplate,"unconfiguredLogTemplate"); AddCmd("log", LogAction); diff --git a/logv2.h b/logv2.h index aa2bd82a..07a84f10 100644 --- a/logv2.h +++ b/logv2.h @@ -110,7 +110,7 @@ void RemoveLogCallback(LogCallback func); * \param subsystem the subsystem of the message * \return 1 when filtered, 0 else */ -unsigned int logFilter(unsigned int severity, const char *subsystem); +unsigned int logFilter(unsigned int severity, const char *subsystem, const char *logMessage); /* *Disable logging in support of the nolog option in SICSmain.c */