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()
|
val previousHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
||||||
try {
|
try {
|
||||||
Timber.e(throwable, "Uncaught exception in %s", thread.name)
|
store.writeCrash(thread, throwable)
|
||||||
store.flush()
|
} catch (logError: Exception) {
|
||||||
|
Log.e("PurefinLogger", "Failed to write uncaught exception to log file", logError)
|
||||||
} finally {
|
} finally {
|
||||||
if (previousHandler != null) {
|
if (previousHandler != null) {
|
||||||
previousHandler.uncaughtException(thread, throwable)
|
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
|
@Synchronized
|
||||||
fun flush() {
|
fun flush() {
|
||||||
directory.mkdirs()
|
directory.mkdirs()
|
||||||
|
|||||||
Reference in New Issue
Block a user