Reputation: 7
I have a multi-modular project, I need to send Timber logs to Crashlytics, but they are not sent, maybe I wrote something wrong. Timber version 5.0.1
class TimberReleaseTree : Timber.Tree() {
override fun isLoggable(tag: String?, priority: Int): Boolean {
return priority == Log.WARN || priority == Log.ERROR
}
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (isLoggable(tag, priority)) {
FirebaseCrashlytics.getInstance().log("$tag: $message")
t?.let { FirebaseCrashlytics.getInstance().recordException(it) }
}
}
}
Upvotes: 0
Views: 594
Reputation: 11110
I would like to share a gist that I use in my own projects.
private class CrashlyticsTree : Timber.Tree() {
override fun isLoggable(tag: String?, priority: Int): Boolean {
return priority == Log.WARN || priority == Log.ERROR
}
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
FirebaseCrashlytics.getInstance().log("$tag: $message")
if (t != null) {
FirebaseCrashlytics.getInstance().recordException(t)
}
}
}
Upvotes: 0
Reputation: 28845
Make sure you have built non-debuggable application or comment first lines if you use this code:
private fun init() {
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
} else {
Timber.plant(CrashlyticsTree()) // Will send to Firebase
}
}
As said in Firebase Crashlytics custom log does not appear in the console FirebaseCrashlytics.getInstance().log
won't send a log.
Check a right package and clear filter.
Upvotes: 0