0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Timberを使ってFirebase Crashlyticsに直接送るLogを送る

Posted at

実装

class CrashlyticsTree : Timber.Tree() {
    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
        if (priority >= Log.ERROR) {
            FirebaseCrashlytics.getInstance().log("$tag: $message")
            t?.let { FirebaseCrashlytics.getInstance().recordException(it) }
        }
    }
}

上記クラスを作成して、Applicationクラスに以下のように追加することで通常通りTimberを使用しながら自動でTimber.e(Throwable)するだけで自動送信されます。

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()

        if (BuildConfig.DEBUG) {
            // デバッグ時は通常のログ出力
            Timber.plant(Timber.DebugTree())
        } else {
            // リリース時はCrashlyticsTreeを使う
            Timber.plant(CrashlyticsTree())
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?