Added a feature which allows suppression of certain log messages. For example TRANSACT messages
This commit is contained in:
36
logv2.c
36
logv2.c
@ -32,6 +32,8 @@ static unsigned int globalLogLevel = INFO;
|
|||||||
|
|
||||||
/*========= The list of sub systems for which full logging is enabled ==========*/
|
/*========= The list of sub systems for which full logging is enabled ==========*/
|
||||||
unsigned int logEnabledArray[MAXSUB ];
|
unsigned int logEnabledArray[MAXSUB ];
|
||||||
|
/*========== A list of entries to suppress =====================================*/
|
||||||
|
int suppressList;
|
||||||
|
|
||||||
/*================== Callback management =======================================*/
|
/*================== Callback management =======================================*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -243,7 +245,7 @@ void formatSubsystem(unsigned int sub, char *buffer, unsigned int bufferLength)
|
|||||||
strncpy(buffer,subText[sub],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;
|
int status;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
@ -253,6 +255,18 @@ unsigned int logFilter(unsigned int severity, const char *subsystem)
|
|||||||
return 1;
|
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
|
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);
|
notifyListeners(severity,subsystem,timeText, logMessage);
|
||||||
|
|
||||||
|
|
||||||
if(logFilter(severity,subsystem) == 1){
|
if(logFilter(severity,subsystem,(const char *)logMessage) == 1){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,6 +669,21 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics,
|
|||||||
SCWrite(pCon,GetCharArray(result),eValue);
|
SCWrite(pCon,GetCharArray(result),eValue);
|
||||||
DeleteDynString(result);
|
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 {
|
} else {
|
||||||
SCPrintf(pCon,eError,"ERROR: unknown keyword %s",argv[1]);
|
SCPrintf(pCon,eError,"ERROR: unknown keyword %s",argv[1]);
|
||||||
return 0;
|
return 0;
|
||||||
@ -672,7 +701,8 @@ void Logv2Init(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
callbackList = LLDcreate(sizeof(LogCBData));
|
callbackList = LLDcreate(sizeof(LogCBData));
|
||||||
|
suppressList = LLDstringCreate();
|
||||||
strcpy(logTemplate,"unconfiguredLogTemplate");
|
strcpy(logTemplate,"unconfiguredLogTemplate");
|
||||||
|
|
||||||
AddCmd("log", LogAction);
|
AddCmd("log", LogAction);
|
||||||
|
2
logv2.h
2
logv2.h
@ -110,7 +110,7 @@ void RemoveLogCallback(LogCallback func);
|
|||||||
* \param subsystem the subsystem of the message
|
* \param subsystem the subsystem of the message
|
||||||
* \return 1 when filtered, 0 else
|
* \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
|
*Disable logging in support of the nolog option in SICSmain.c
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user