18 #include "StarOptionFilter.h"
19 #include <log4cxx/spi/loggingevent.h>
20 #include <log4cxx/helpers/optionconverter.h>
24 using namespace log4cxx;
25 using namespace log4cxx::varia;
26 using namespace log4cxx::spi;
27 using namespace log4cxx::helpers;
39 ,currentRepeatCounter(0),currentTotalCounter(0)
40 ,matchPredefinedStringOnly(false)
45 void StarOptionFilter::setOption(
const String& option,
50 if (equalsIgnoreCase(option, ACCEPT_REPEAT_COUNTER))
52 acceptRepeatCounter = OptionConverter::toInt(value,acceptRepeatCounter);
54 else if (equalsIgnoreCase(option,STRING_TO_COUNT_OPTION))
56 if ( lastLoggerMessageToCompare != value) {
57 currentRepeatCounter = 0;
58 lastLoggerMessageToCompare = value;
59 matchPredefinedStringOnly =
true;
61 if (lastLoggerMessageToCompare.empty())
62 matchPredefinedStringOnly =
false;
64 else if (equalsIgnoreCase(option,TOTAL_MESSAGE_LIMIT))
66 acceptTotalCounter = OptionConverter::toInt(value,acceptTotalCounter);
70 void StarOptionFilter::setRepeatCounterOption(
int value)
80 acceptRepeatCounter = value;
84 void StarOptionFilter::setTotalCounterOption(
int value)
93 acceptTotalCounter = value;
96 Filter::FilterDecision StarOptionFilter::decide(
97 const log4cxx::spi::LoggingEventPtr& event)
const
99 Filter::FilterDecision decision = Filter::NEUTRAL;
100 const String& msg =
event->getRenderedMessage();
105 if ( (acceptRepeatCounter >= 0 ) || (acceptTotalCounter >= 0 ) )
107 bool count = !matchPredefinedStringOnly
109 (matchPredefinedStringOnly && strstr(msg.c_str(),lastLoggerMessageToCompare.c_str())) ;
111 if (acceptRepeatCounter >= 0 ) currentRepeatCounter++;
112 if (acceptTotalCounter >= 0 ) currentTotalCounter++;
115 currentRepeatCounter = 0;
116 if (!matchPredefinedStringOnly && (acceptRepeatCounter >= 0 ) )
117 lastLoggerMessageToCompare = msg;
120 if( count && (acceptRepeatCounter >=0 ) && (currentRepeatCounter > acceptRepeatCounter) )
121 decision = Filter::DENY;
123 if( count && (acceptTotalCounter >=0) && (currentTotalCounter > acceptTotalCounter) )
124 decision = Filter::DENY;
127 if (acceptRepeatCounter >= 0 ) {
128 if( strcmp(msg.c_str(),lastLoggerMessageToCompare.c_str() ) )
130 if (!matchPredefinedStringOnly) {
131 currentRepeatCounter = 2;
132 lastLoggerMessageToCompare = msg;
138 if(currentRepeatCounter > acceptRepeatCounter) decision = Filter::DENY;
139 currentRepeatCounter++;