Last active
October 3, 2018 16:25
-
-
Save alwarren/b37e0aae66d0e9edc08e5ea6d8b2f0c7 to your computer and use it in GitHub Desktop.
A Custom Timber Debug Tree with Prepended Tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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