We have noticed that if an exception is thrown while CDI events are being processed - for example with @Observes(during = TransactionPhase.BEFORE_COMPLETION)
- then the exception is not logged if the log level is above DEBUG
.
Weld logs something simple like this:
16:31:41,732 ERROR [org.jboss.weld.Event] WELD-000401 Failure while notifying an observer of event SomeEventDTO
Lines 85-86 of the DeferredEventNotification
from Weld show the problem: https://github.com/weld/core/blob/master/modules/jta/src/main/java/org/jboss/weld/module/jta/DeferredEventNotification.java
} catch (Exception e) {
EventLogger.LOG.asyncObserverFailure(metadata);
EventLogger.LOG.catchingDebug(e);
}
Is this because the specs say the exception and its stacktrace don't need to be logged, or is this because Weld is rather (too) relaxed in its handling of exceptions.
Is there a better solution than wrapping all event observing code with a try-catch block?
Note: setting the standard Log Level for org.jboss.weld.Event
to DEBUG
causes a little too much logging. Each sent event is also logged:
17:47:14,088 DEBUG [org.jboss.weld.Event] WELD-000400 Sending event SomeEventDTO directly to observer [method] public com.foo.bar.BeanClass.methodName(SomeEventDTO)
Now that I understand your question (sorry for the confusion before), let me shed some light.
The error message seems to be intentionally hidden by Weld. There are no specification restraints on logging whatsoever. As far as exceptions are concerned, the specification merely describes what should blow up and when.
Also, you are using Weld JTA module which I think does not correspond to any CDI spec part (meaning its Weld-specific) so it might not have a say there anyway.
Now to the solution, I think you have a fair point with the logging, it doesn't really help. Therefore, I went ahead and created a JIRA issue (WELD-2330). Since this is 3.x branch, it should be fixed pretty quickly. Feel free to jump in and have a say in it or even contribute.