mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
feat(logging): improve uncaught exception handling with dedicated logging method
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user