This project shows how to set up Firebase Crashlytics with the awesome logger API Timber
- Get crash reports
- Get non-fatal errors into Firebase Crashlytics dashboard in an easy way with Timber
- Disable sending the reports to Firebase Crashlytics in
DEBUG
mode
- Install Firebase Crashlytics (documentation)
- Install Timber
implementation 'com.jakewharton.timber:timber:4.7.1'
- Add a custom
Timber.Tree
class CrashlyticsTree : Timber.Tree() {
private val KEY_PRIORITY = "priority"
private val KEY_TAG = "tag"
private val KEY_MESSAGE = "message"
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
when (priority) {
Log.VERBOSE, Log.DEBUG, Log.INFO -> return
else -> {
Crashlytics.setInt(KEY_PRIORITY, priority)
Crashlytics.setString(KEY_TAG, tag)
Crashlytics.setString(KEY_MESSAGE, message)
if (t == null) {
Crashlytics.logException(Exception(message))
} else {
Crashlytics.logException(t)
}
}
}
}
- Install and integrate Firebase Crashlytics with Timber in your
Application
class
val crashlytics = CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
.build()
Fabric.with(this, Crashlytics.Builder().core(crashlytics).build())
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
Timber.plant(CrashlyticsTree())
see more at App.kt
- A crash will be reported automatically
- Logs a non-fatal via
Timber.e()
orTimber.w()
Leave a Reply