Add ability to log non-fatal errors (#3417)

This commit is contained in:
David Perez 2024-07-09 10:02:36 -05:00 committed by GitHub
parent adf7916a4c
commit 65237c18d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View file

@ -11,4 +11,6 @@ class CrashLogsManagerImpl(
legacyAppCenterMigrator: LegacyAppCenterMigrator, legacyAppCenterMigrator: LegacyAppCenterMigrator,
) : CrashLogsManager { ) : CrashLogsManager {
override var isEnabled: Boolean = true override var isEnabled: Boolean = true
override fun trackNonFatalException(e: Exception) = Unit
} }

View file

@ -9,4 +9,9 @@ interface CrashLogsManager {
* Gets or sets whether the collection of crash logs is enabled. * Gets or sets whether the collection of crash logs is enabled.
*/ */
var isEnabled: Boolean var isEnabled: Boolean
/**
* Tracks an exception if logs are enabled.
*/
fun trackNonFatalException(e: Exception)
} }

View file

@ -22,6 +22,12 @@ class CrashLogsManagerImpl(
Firebase.crashlytics.setCrashlyticsCollectionEnabled(value) Firebase.crashlytics.setCrashlyticsCollectionEnabled(value)
} }
override fun trackNonFatalException(e: Exception) {
if (settingsRepository.isCrashLoggingEnabled) {
Firebase.crashlytics.recordException(e)
}
}
init { init {
legacyAppCenterMigrator.migrateIfNecessary() legacyAppCenterMigrator.migrateIfNecessary()
isEnabled = settingsRepository.isCrashLoggingEnabled isEnabled = settingsRepository.isCrashLoggingEnabled