elvishew/xLog

All Exceptions changed ANR

Godsbox opened this issue · 1 comments

all execptions will frozen stil ANR. For example, NullPointerException

Code :
LogConfiguration config = new LogConfiguration
.Builder()
.logLevel(LogLevel.ALL)
.tag(TAG)
.build();
String logPath = Environment.getExternalStorageDirectory() + File.separator + "shanyi" + File.separator + "/log/";
Printer filePrinter = new FilePrinter
.Builder(logPath)
.fileNameGenerator(new LogFileNameGenerator())
.flattener(new LogFileFormat())
.build();
if (BuildConfig.DEBUG) {
XLog.init(config, new AndroidPrinter(), filePrinter);
} else {
XLog.init(config, filePrinter);
}
Thread.setDefaultUncaughtExceptionHandler((thread, e) -> {
XLog.st(10).e("程序崩溃退出", e);
Log.e(TAG, "程序崩溃退出", e);
});

@Godsbox Seems your code is wrong

Try in this way instead

Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler((thread, e) -> {
            XLog.st(10).e("程序崩溃退出", e);
            Log.e(TAG, "程序崩溃退出", e);

            if (handler != null) {
                handler.uncaughtException(thread, e);
            }
        });