forked from github/wulkanowy-mirror
Migrate from fabric to firebase crashlytics (#789)
This commit is contained in:
@ -1,36 +1,46 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.crashlytics.android.core.CrashlyticsCore
|
||||
import fr.bipi.tressence.crash.CrashlyticsLogExceptionTree
|
||||
import fr.bipi.tressence.crash.CrashlyticsLogTree
|
||||
import io.fabric.sdk.android.Fabric
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import fr.bipi.tressence.base.FormatterPriorityTree
|
||||
import fr.bipi.tressence.common.StackTraceRecorder
|
||||
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
fun initCrashlytics(context: Context, appInfo: AppInfo) {
|
||||
Fabric.with(Fabric.Builder(context)
|
||||
.kits(
|
||||
Crashlytics.Builder()
|
||||
.core(CrashlyticsCore.Builder()
|
||||
.disabled(!appInfo.isCrashlyticsEnabled)
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.debuggable(appInfo.isDebug)
|
||||
.build())
|
||||
}
|
||||
class CrashlyticsTree : FormatterPriorityTree(Log.VERBOSE) {
|
||||
|
||||
class CrashlyticsTree : CrashlyticsLogTree(Log.VERBOSE) {
|
||||
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
|
||||
|
||||
override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean {
|
||||
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) {
|
||||
return true
|
||||
}
|
||||
|
||||
return super.skipLog(priority, tag, message, t)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) return
|
||||
if (skipLog(priority, tag, message, t)) return
|
||||
|
||||
super.log(priority, tag, message, t)
|
||||
crashlytics.log(format(priority, tag, message))
|
||||
}
|
||||
}
|
||||
|
||||
class CrashlyticsExceptionTree : CrashlyticsLogExceptionTree()
|
||||
class CrashlyticsExceptionTree : FormatterPriorityTree(Log.ERROR) {
|
||||
|
||||
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
if (skipLog(priority, tag, message, t)) return
|
||||
|
||||
crashlytics.setCustomKey("priority", priority)
|
||||
crashlytics.setCustomKey("tag", tag.orEmpty())
|
||||
crashlytics.setCustomKey("message", message)
|
||||
if (t != null) {
|
||||
crashlytics.recordException(t)
|
||||
} else {
|
||||
crashlytics.recordException(StackTraceRecorder(format(priority, tag, message)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user