0

I am using custom ReleaseTree for my application using Timber to filter the logs. But when building the release apk application logs are not showing in logcat. When using Timber.DebugTree() in release build logs are showing properly.

Here is my ReleaseTree class:

class ReleaseTree : Timber.Tree() {

    override fun log(priority: Int, tag: String?, message: String, throwable: Throwable?) {
        // Don't log VERBOSE, DEBUG and INFO
        if (priority == Log.VERBOSE) {
            return
        }


        if (priority == Log.ERROR){
            val t = throwable ?: Exception(message)

            // Crashlytics
            Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority)
            Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag)
            Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message)
            Crashlytics.logException(t)
        }

    }

    companion object {
        private val CRASHLYTICS_KEY_PRIORITY = "Priority"
        private val CRASHLYTICS_KEY_TAG = "Tag"
        private val CRASHLYTICS_KEY_MESSAGE = "Message"
    }
}

How I am initializing the ReleaseTree from Application class:

Fabric.with(this, new Crashlytics());
Timber.plant(new ReleaseTree());
4

1 回答 1

1

您的方法日志中缺少一行。

您需要从自定义树登录到 logcat

override fun log(priority: Int, tag: String?, message: String, throwable: Throwable?) {
        // Don't log VERBOSE, DEBUG and INFO
        if (priority == Log.VERBOSE) {
            return
        } else {
          Log.println(priority, tag, message);
        }


        if (priority == Log.ERROR){
            val t = throwable ?: Exception(message)

            // Crashlytics
            Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority)
            Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag)
            Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message)
            Crashlytics.logException(t)
        }

    }

于 2019-03-01T13:52:53.253 回答