28
Log.i("Test", "Hello, Log")
Timber.i("Hello, Timber")

I can see the Log.i log in Debug console and Logcat, I don't see the Timber log in anywhere.

I/Test: Hello, Log

I'm building in stagingDebug mode. (I have 4 options, production debug and release and staging debug and release)

What I'm missing?

Expert wanna be
  • 10,218
  • 26
  • 105
  • 158

5 Answers5

45

Make sure that you have initialised Timber in Application class. Following code might help :-

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // This will initialise Timber
        if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
        }
   }
}
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
15

If you're initializing Timber like this:

if (BuildConfig.DEBUG) {
    Timber.plant(Timber.DebugTree())
}

Be sure, that you're imported BuildConfig from your app package, and not something like BuildConfig's from 3rd party libraries like this: import org.koin.android.BuildConfig. I strugled with this a few times.

sizeofanton
  • 151
  • 2
  • 7
13

initialization Timber in Kotlin

class ExampleApplication : Application(){

    override fun onCreate() {
        super.onCreate()
        // init timber
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}

and don't forget write android:name of Application in Manifest.xml:

<application
        android:name=".ExampleApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PostMakerMassive">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
Arsen Tagaev
  • 411
  • 7
  • 13
5

In my case, I imported the incorrect BuildConfig. You can check if that is the issue with yours as well.

Alankrita Shah
  • 101
  • 2
  • 5
1

Try to add tag in Timber. It should be set (automatically) based on the information in the Manifest, but it does not always happen (e.g. for custom devices with custom OS)

So first of all plant it:

// Java
Timber.plant(new Timber.DebugTree());

// Kotlin
Timber.plant(Timber.DebugTree())

and next set tag:

// custom tag
Timber.tag("your custom tag");

// or
Timber.tag("trolololololo");

// or something (more serious) from strings:
Timber.tag(getString(R.string.app_name))
Boken
  • 4,825
  • 10
  • 32
  • 42