Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - grouping identical exceptions in logs

Is there any logging solution with exception grouping feature? What I want to achieve is when some exception is logged for example 100 times in 10 seconds I don't want to log 100 stack traces. I want to log something like RuntimeException was thrown 100 times: single stack trace here. It'd perfect to have something integrated with log4j.

Ofc there is an option to create some logging facade with exception queue inside but maybe there is something already implemented.

like image 388
coolguy Avatar asked Jun 20 '16 13:06

coolguy


1 Answers

Please take a look at this log handler implementation that groups logs for then sending to an email address.

The solution is basically a log handler that uses a CyclicBuffer to save logs to memory. When a threshold is reached or the system is closes, the handler flushes the buffer.

The solution is JUL based (java.util.logging), but it may serve you as basis for you to build your own log4j solution with a few modifications. It worked nice for me. Hope it helps.

like image 165
Andrés Oviedo Avatar answered Nov 03 '22 21:11

Andrés Oviedo