feat(logging): improve uncaught exception handling with dedicated logging method

This commit is contained in:
2026-05-14 18:24:56 +02:00
parent c70657e627
commit 1fc2c8cf05

View File

@@ -48,8 +48,9 @@ object PurefinLogger {
val previousHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
try {
Timber.e(throwable, "Uncaught exception in %s", thread.name)
store.flush()
store.writeCrash(thread, throwable)
} catch (logError: Exception) {
Log.e("PurefinLogger", "Failed to write uncaught exception to log file", logError)
} finally {
if (previousHandler != null) {
previousHandler.uncaughtException(thread, throwable)
@@ -98,6 +99,16 @@ private class LogFileStore(
}
}
@Synchronized
fun writeCrash(thread: Thread, throwable: Throwable) {
write(
priority = Log.ERROR,
tag = "UncaughtException",
message = "Uncaught exception in ${thread.name}",
throwable = throwable,
)
}
@Synchronized
fun flush() {
directory.mkdirs()