Skip to content

Instantly share code, notes, and snippets.

@alwarren
Last active October 3, 2018 16:25
Show Gist options
  • Save alwarren/b37e0aae66d0e9edc08e5ea6d8b2f0c7 to your computer and use it in GitHub Desktop.
Save alwarren/b37e0aae66d0e9edc08e5ea6d8b2f0c7 to your computer and use it in GitHub Desktop.
A Custom Timber Debug Tree with Prepended Tags
import android.os.Build
import timber.log.Timber
const val TIMBER_TAG = "--->"
const val MAX_TAG_LENGTH = 23
class TimberDebugTree : Timber.DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String? {
val tag = TIMBER_TAG + super.createStackElementTag(element)
return if (tag.length <= MAX_TAG_LENGTH || Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
tag
} else tag.substring(0, MAX_TAG_LENGTH)
}
}
import android.app.Application
import timber.log.Timber
import TimberDebugTree
class App: Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(TimberDebugTree())
}
}
}
ext.versions = [
timber : '4.7.1',
]
dependencies {
implementation "com.jakewharton.timber:timber:$versions.timber"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment