Timber is a logging utility class built on top of Android’s Log class. While in development, we usually end up writing lot of log statements and before the release, we’ll cleanup the log statements by removing them manually (even though logs can be disabled in release build). This tedious process can be avoided easily by using Timber.

Timber provides lots of other options as well. Let’s see how it can be used in our projects to maintain the logs better.


1. Timber

Below are few debug statements printed using default Log class.

int a = 100;
Log.e("TAG", String.format("Integer a value is: %d", a));

String name = "Android Studio";
Log.e("TAG", String.format("My name is: %s", name));

The above same statements can be printed using Timber as below.

// integer
int a = 100;
Timber.d("Integer a value is: %d", a);

String name = "Android Studio";
Timber.d("My name is: %s", name);
  • You can notice here, the TAG is not passed to Timber as it automatically detects the class in which logs were written.
  • Also String formatter is not used to format the statement as Timber can do it automatically for you.

2. Integrating Timber

Now let’s see how to integrate Timber library in your project making it available in every class.

1. Create a new project in Android Studio from File ⇒ New Project and select Basic Activity from templates.

2. Open build.gradle and add Timber dependency. Butterknife is optional here, but required for this example.

    // timber
    implementation 'com.jakewharton.timber:timber:4.7.1'

    // butter knife
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

3. Timber has to be initialized as soon as app starts. So, Application class would be best place to do that. Create new class named MyApplication.java and extend the class from Application.

  • Initialize Timber in onCreate method by planting a new Tree.
  • Here Timber.DebugTree() prints logs in debug mode.
  • If you want to catch exceptions in release mode, you can create a different Tree and plant it in release mode. This step is completely optional but if you want to send exceptions to a different service, this is the appropriate place to do it.
package info.androidhive.timber;

import android.app.Application;

import info.androidhive.timber.log.ReleaseTree;
import timber.log.Timber;

public class MyApplication extends Application {
    public void onCreate() {

        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
        } else {
            Timber.plant(new ReleaseTree());

4. You can create a custom tree by extending the class from Timber.Tree. Here is the example of ReleaseTree.java class.

package info.androidhive.timber.log;

import android.util.Log;

import timber.log.Timber;

public class ReleaseTree extends Timber.Tree {
    protected void log(int priority, String tag, String message, Throwable t) {
        if (priority == Log.VERBOSE || priority == Log.DEBUG) {

        // log your crash to your favourite
        // Sending crash report to Firebase CrashAnalytics

        // FirebaseCrash.report(message);
        // FirebaseCrash.report(new Exception(message));

4. Finally add MyApplication to your <application> tag in your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"




5. Now, Timber is ready to use in your app. Below are few examples of Timber log statements demonstrating different scenarios.

package info.androidhive.timber;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import timber.log.Timber;

public class MainActivity extends AppCompatActivity {

    private Unbinder unbinder;

    protected void onCreate(Bundle savedInstanceState) {
        unbinder = ButterKnife.bind(this);

        Toolbar toolbar = findViewById(R.id.toolbar);

        // boolean
        boolean isWeekend = false;
        Timber.d("This prints the boolean value. Is weekend: %b", isWeekend);

        // integer
        int a = 100;
        Timber.d("Integer a value is: %d", a);

        // float
        float pi = 3.14159f;
        Timber.d("Pi value is: %f", pi);

    void logMessage() {
        Timber.d("Hello from Timber!");


    void logException() {
        try {
            int a = 10 / 0;
            Timber.d("Value of a: %d", a);
        } catch (Exception e) {

            // or //

            Timber.e("Exception in math operation: %s", e.getMessage());


    private void showToast() {
        Toast.makeText(getApplicationContext(), "Check LogCat for message or error!", Toast.LENGTH_SHORT).show();

    protected void onDestroy() {
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info
  • Francis Ng’wandu

    Great tutorial. Thanks for sharing…

  • Sagar Bandamwar

    always been great experience visiting and following ravi

  • Lobot Hijau

    Firebase Analytics is automatically detect crash without any configuration. Is it still necessary for Timber to send crash report to Firebase where Firebase itself already able to do the same?

    • Not it’s not necessary. It’s just example. In real app you might wanna use that block for something else.

  • I don’t have article written. But you can try from here.

  • Jankari Hindi

    Ravi Why You’r SLACK COMMUNITY not Work Link has been Brocked.Please Check… I am Wants to ask something with You.

  • Dayakar Puli

    Can you post background location tracking for fitness. It will work in all mobile versions

  • Rajasekaran T

    Ravi, I already request you to teach us about Raspberry PI.

    • Patricia M. jessy

      watch aquaman HD 2018 (available 1080p) . with the best quality and all languange….

  • Pawan Soni

    timber is also third Party Library. so what if Library will deprecate?

    • We can’t do anything about it. But it’s very popular one, so won’t be deprecated until there is better solution.

  • AbelardoLG

    What if our login data are stored into Timber’s database? :O

    • What do you mean by Timber database?

      • AbelardoLG

        Hi Ravi,

        I meant that any piece of data transferred by using this library will be copied into Timber database.

  • test android

    Very nice tutorial. Thank You.
    In release build it still logs the data. How can I resolve it ?

  • Thanks for the post, really informative

  • prince

    i want to know how to add multiple images so that it can be loaded in app like amazon do. For eg if we search for shoes it show thousands of images

  • Why is findViewById() used for toolbar instead of ButterKnife? Is this intentional?