From 1fc2c8cf05aa0e80a88e74246bd75ab4d4a437df Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Thu, 14 May 2026 18:24:56 +0200 Subject: [PATCH] feat(logging): improve uncaught exception handling with dedicated logging method --- .../bbara/purefin/core/logging/PurefinLogger.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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()