Expert wanna be
Expert wanna be

Reputation: 10624

Timber log is not printing in debug console or Logcat

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?

Upvotes: 31

Views: 15963

Answers (5)

Arsen Tagaev
Arsen Tagaev

Reputation: 449

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>

Upvotes: 15

Rohan Kandwal
Rohan Kandwal

Reputation: 9336

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 initialize Timber
            if (BuildConfig.DEBUG) {
                Timber.plant(new Timber.DebugTree());
            }
       }
    }

Upvotes: 49

Boken
Boken

Reputation: 5454

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

Upvotes: 1

Alankrita Shah
Alankrita Shah

Reputation: 101

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

Upvotes: 5

sizeofanton
sizeofanton

Reputation: 161

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.

Upvotes: 16

Related Questions