Logging uncaught exceptions in threads created by third-party code in web application
-
13-06-2021 - |
質問
I suspect a thread created by a third-party jar used by my web application may be throwing an exception, and not catching it. However, I don't see any evidence of this in the log files. How can I force all uncaught exceptions to be dumped to a log file? This is for a web app running inside Glassfish.
解決 3
It turns out that this is not necessary with Glassfish, because Glassfish already does it - but I was looking at the wrong place in the logs.
The exception was printed to the main server.log
file - not to my application's own log4j log file.
他のヒント
You can change the uncaught exception handler.
http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html
You can set a default uncaught exception handler using Thread's
setDefaultUncaughtExceptionHandler
static method:
Thread.setDefaultUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() {
public void uncaughtException( final Thread t, final Throwable e ) {
...