diff --git a/core/src/main/java/hu/bbara/purefin/core/logging/PurefinLogger.kt b/core/src/main/java/hu/bbara/purefin/core/logging/PurefinLogger.kt index cade1bb5..cc986c95 100644 --- a/core/src/main/java/hu/bbara/purefin/core/logging/PurefinLogger.kt +++ b/core/src/main/java/hu/bbara/purefin/core/logging/PurefinLogger.kt @@ -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()