在调试控制台或Logcat中未打印木材日志

Exp*_* be 6 timber-android

Log.i("Test", "Hello, Log")
Timber.i("Hello, Timber")
Run Code Online (Sandbox Code Playgroud)

我可以在调试控制台和Logcat中看到Log.i日志,但在任何地方都看不到Timber日志。

I /测试:您好,日志

我正在以stagingDebug模式构建。(我有4个选项,生产调试和发布以及暂存调试和发布)

我想念的是什么?

Ars*_*aev 14

Kotlin 中的初始化 Timber

class ExampleApplication : Application(){

    override fun onCreate() {
        super.onCreate()
        // init timber
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并且不要忘记android:name在 Manifest.xml 中写入 Application:

<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>
Run Code Online (Sandbox Code Playgroud)


Roh*_*wal 10

确保您已TimberApplication课堂上进行了初始化。以下代码可能有帮助:-

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // This will initialise Timber
        if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
        }
   }
}
Run Code Online (Sandbox Code Playgroud)

  • @claytonjwong 这是 Java 代码,Kotlin 不需要 new (3认同)

小智 8

如果您像这样初始化 Timber:

if (BuildConfig.DEBUG) {
    Timber.plant(Timber.DebugTree())
}
Run Code Online (Sandbox Code Playgroud)

请确保您是从应用程序包中导入 BuildConfig 的,而不是像这样的 3rd 方库中的 BuildConfig 之类的:import org.koin.android.BuildConfig. 我为此挣扎了几次。


小智 5

就我而言,我导入了不正确的 BuildConfig。您可以检查一下是否也是您的问题。