crashlytics-sample

Crashlytics and Timber combinations


This project shows how to set up Firebase Crashlytics with the awesome logger API Timber

Features

  • 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

How to setup

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

How to use

  • A crash will be reported automatically
  • Logs a non-fatal via Timber.e() or Timber.w()

Credit

Visit original content creator repository
https://github.com/thuongleit/crashlytics-sample

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *