Timber

Learn more about the Sentry Timber integration for the Android SDK.

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.

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
plugins {
  id "io.sentry.android.gradle" version "4.6.0"
}

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.

If you want to disable the Timber integration (to not exceed your event quota, for example), but keep using other auto-installation features, remove the sentry-android-timber dependency from the app configurations in app/build.gradle:

Copied
configurations.configureEach {
  exclude group: "io.sentry", module: "sentry-android-timber"
}

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:7.9.0'
implementation 'io.sentry:sentry-android-timber:7.9.0'

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())
  }
}

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);
    }
  }
}

Learn more about manually capturing an error or message, in our Usage documentation.

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!) or suggesting an update ("yeah, this would be better").