mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
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
|
||||
// slf4j may be implicitly initialized before we properly configured it.
|
||||
setupLogging();
|
||||
|
||||
setupExceptionHandler();
|
||||
// For debugging problems with the logback configuration
|
||||
// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
// print logback's internal status
|
||||
@ -67,6 +69,11 @@ public class GBApplication extends Application {
|
||||
// db.close();
|
||||
}
|
||||
|
||||
private void setupExceptionHandler() {
|
||||
LoggingExceptionHandler handler = new LoggingExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
|
||||
Thread.setDefaultUncaughtExceptionHandler(handler);
|
||||
}
|
||||
|
||||
public static boolean isFileLoggingEnabled() {
|
||||
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
Block a user