3 ms·
> To put that another way, you might not know at the time whether your function is going to be invoked from a high-throughput loop. > Is there a nice solution
by wsargent 6y ago
> To put that another way, you might not know at the time whether your function is going to be invoked from a high-throughput loop.
> Is there a nice solution to this problem?
There's two ways to do it from within the logging framework. The first way is that you can suppress duplicate messages with a filter, like the DuplicateMessageFilter [1]. It wouldn't be that hard to add a filter that looked for the message template, and could suppress based on other properties on the LoggingEvent, such as the request ID or the overall similarity of the event.
The second thing you can do is add a budget for your logger, which will only allow it to log a certain period in a window. This is something you can do with budget evaluators [2].
Depending on the layer you put over SLF4J, you can also add conditional logging [3], which puts the logic at the application layer. Under this model, you'd have a counter or circuit breaker in the condition that would short-circuit the logging.
[1] http://logback.qos.ch/manual/filters.html#DuplicateMessageFilter http://logback.qos.ch/manual/filters.html#DuplicateMessageFi...
[2] https://tersesystems.github.io/terse-logback/guide/budget/ https://tersesystems.github.io/terse-logback/guide/budget/
[3] https://tersesystems.github.io/blindsight/usage/conditional.html https://tersesystems.github.io/blindsight/usage/conditional....