Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce logging of the same exceptioins

Are there any smart ways to reduce logging of "equals" exceptions?

For example:

java.lang.IllegalArgumentException: Wrong parameter, should be a float from 0 to 100
at com.test.Foo.setAmount(Foo.java:93)
at com.test.Bar.setAmounts(Bar.java:39)
at com.test.Bar2.init(Bar2.java:152)
at java.awt.event.InvocationEvent.dispatch(Unknown Source) [na:1.7.0_65]
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) [na:1.7.0_65]
at java.awt.EventQueue.access$200(Unknown Source) [na:1.7.0_65]
at java.awt.EventQueue$3.run(Unknown Source) [na:1.7.0_65]
at java.awt.EventQueue$3.run(Unknown Source) [na:1.7.0_65]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_65]
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) [na:1.7.0_65]
at java.awt.EventQueue.dispatchEvent(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.run(Unknown Source) [na:1.7.0_65]

such exception can be thrown 90 times per second under specific circumstances. We use AWT handler to log exceptions, and it can "freeze" all Swing's application.

The first workaround which came to mind was to log exceptions in a different thread, but such approch may be a real hell in later debug.

The second thought was to put exceptions in a WeakHashMap and log exception only for first occurance. Im not sure how to perform equals for exception and whether it will be fast enough at all.

like image 728
Vladimir Kishlaly Avatar asked Dec 15 '25 06:12

Vladimir Kishlaly


1 Answers

If you want to use Logback, there is a Filter called DuplicateMessageFilter that drops messages after a certain repetition.

like image 148
Stefan Avatar answered Dec 16 '25 21:12

Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!