Ensure uncaught exceptions are logged into server error log

Normally these go to stdout, but in daemon mode that is usually
the useless /dev/null device.

Bug: issue 483
Change-Id: Ida8d0c91744410b316ba32834a2307b10bc312f8
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-03-04 19:01:36 -08:00
parent 11c4bf8ec6
commit f28c6952a2
2 changed files with 21 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
import java.util.List;
@@ -91,6 +92,12 @@ public class Daemon extends SiteProgram {
@Override
public int run() throws Exception {
mustHaveValidSite();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
log.error("Thread " + t.getName() + " threw exception", e);
}
});
if (runId != null) {
runFile = new File(new File(getSitePath(), "logs"), "gerrit.run");