Timber

The sentry-android-timber library provides Timber support for Sentry via Timber Tree that sends events and breadcrumbs to Sentry. Once this integration is configured you can use Timber’s static API.

The source can be found on GitHub.

Auto-Installation With the Sentry Android Gradle Plugin

Install

Starting from version 3.1.0, the Sentry Android Gradle plugin will automatically add the sentry-android-timber dependency. The plugin will only add the sentry-android-timber dependency if a timber dependency was discovered on the classpath.

Add the Sentry Android Gradle plugin in build.gradle:

Copied
buildscript {
  repositories {
    mavenCentral()
  }
}

plugins {
  id "io.sentry.android.gradle" version "3.1.6"
}

Then, initialize the Android SDK.

The Android SDK automatically adds the SentryTimberIntegration if the sentry-android-timber dependency was found on the classpath. The integration is added with minEventLevel set to ERROR and minBreadcrumbLevel set to INFO.

However, you can still override the default behaviour by adding your own instance of the SentryTimberIntegration. For that, refer to the manual installation section below.

Manual Installation

Install

To add the Timber integration, manually initialize the Android SDK, then add the sentry-android-timber dependency. Using Gradle:

Copied
implementation 'io.sentry:sentry-android:6.4.2'
implementation 'io.sentry:sentry-android-timber:6.4.2'

Configure

Configuration should happen as early as possible in your application's lifecycle.

Copied
import io.sentry.android.core.SentryAndroid
import io.sentry.android.timber.SentryTimberIntegration
import timber.log.Timber
// import BuildConfig

SentryAndroid.init(this) { options ->
  if (!BuildConfig.DEBUG) {

    // default values:
    // minEventLevel = ERROR
    // minBreadcrumbLevel = INFO
    options.addIntegration(
      SentryTimberIntegration(
        minEventLevel = SentryLevel.ERROR,
        minBreadcrumbLevel = SentryLevel.INFO
      )
    )
  } else {
    Timber.plant(Timber.DebugTree())
  }
}

Verify

This snippet captures an intentional error, so you can test that everything is working as soon as you set it up:

Copied
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exception
import timber.log.Timber

class MyActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    try {
      throw Exception("This is a test.")
    } catch (e: Exception) {
      Timber.e(e);
    }
  }
}

To view and resolve the recorded message, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").