Log otherwise uncaught exceptions (#134)
This commit is contained in:
parent
600e7d59b5
commit
4533ae22ee
|
@ -52,6 +52,8 @@ public class GBApplication extends Application {
|
||||||
// don't do anything here before we set up logging, otherwise
|
// don't do anything here before we set up logging, otherwise
|
||||||
// slf4j may be implicitly initialized before we properly configured it.
|
// slf4j may be implicitly initialized before we properly configured it.
|
||||||
setupLogging();
|
setupLogging();
|
||||||
|
|
||||||
|
setupExceptionHandler();
|
||||||
// For debugging problems with the logback configuration
|
// For debugging problems with the logback configuration
|
||||||
// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||||
// print logback's internal status
|
// print logback's internal status
|
||||||
|
@ -67,6 +69,11 @@ public class GBApplication extends Application {
|
||||||
// db.close();
|
// db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupExceptionHandler() {
|
||||||
|
LoggingExceptionHandler handler = new LoggingExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isFileLoggingEnabled() {
|
public static boolean isFileLoggingEnabled() {
|
||||||
return sharedPrefs.getBoolean("log_to_file", false);
|
return sharedPrefs.getBoolean("log_to_file", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class LoggingExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(LoggingExceptionHandler.class);
|
||||||
|
private final Thread.UncaughtExceptionHandler mDelegate;
|
||||||
|
|
||||||
|
public LoggingExceptionHandler(Thread.UncaughtExceptionHandler delegate) {
|
||||||
|
mDelegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread thread, Throwable ex) {
|
||||||
|
LOG.error("Uncaught exception: " + ex.getMessage(), ex);
|
||||||
|
if (mDelegate != null) {
|
||||||
|
mDelegate.uncaughtException(thread, ex);
|
||||||
|
} else {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue