Reducing logging of the same exceptions

Are there any clever ways to shorten the 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 an exception can be thrown 90 times per second under certain circumstances. We use an AWT handler to log exceptions, and it can freeze all Swing applications.

The first solution that came to mind was to log exceptions on a different thread, but this approach can be real hell later on in debugging.

The second thought was to throw exceptions from the WeakHashMap and log exception only for the first occurrence. I'm not sure how to execute equals for the exception and if it will be fast enough.

+3


source to share


2 answers


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



+5


source


What if you write an ExceptionWrapper class and implement an equals () method that compares the message and stack traces. The logger then saves a LinkedHashSet of wrappers to which newly thrown exceptions are added. The registrar registers Set, for example. every second (or any other time interval). Thus, newly added "equal" exceptions replace older ones.



+2


source







All Articles