I have a filter which is suppressing repeated messages, if the message was seen more than x times within y seconds for z seconds. With log4j I've put a event scoped MDC property to it once the threshold was reached, like:
event.setProperty( "prefix", suppressProlog );
In my layouts I used then this kind of pattern:
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS z}] %p %t %c %X{prefix} %m%n" />
As this property was limited to the current event, I hadn't to worry about cleaning up. With log4j2, it seems that event linked properties are gone. How would I realize the same behaviour as I had with log4j?
Here's what I see as possible solutions, but none looks very appealing to me:
- I could keep my own ThreadLocal property and clean it up after it was logged, but what when it's being logged through Async Logger within another Thread, or how do I know that this can be cleaned up? And splitting the suppression logic into Filter and Layout seems wrong
- Reading this answer https://stackoverflow.com/a/29597669/1377224, it seems like subclassing LogEvent is discouraged either, so extending LogEvent to provide some suppress flag isn't working. As well I tried to keep away from hacking into log4j this time.
- The filter could log itself a message telling that message x is going to be suppressed. Would it be good practice to have plugins log messages with standard loggers instead of StatusLogger?
What is the anticipated pattern to have filter influence, the logging output?