Debuggers are all well and good, but when you have to break out the debug log statements, they should be powerful!
LogSugar is a small library intended to make debugging via log statements easier.
- Click to jump to where you logged from (like you'd see in stack traces)
- Extension functions for inspecting values
- Measure elapsed time & count occurrences
- ...etc
build.gradle.kts:
implementation("com.github.JeffWright:logsugar:<VERSION>")
(find the latest version here)
Optional: Call this from wherever you want. configure()
has additional options.
LogSugar.configure { tag, message ->
// If you're on Android, this looks good with Android Studio's "compact" view. If you're not, you can use println() or anything else
Log.d("LogSugar", "$tag: $message")
}
Use it:
class LogSugarDemo {
fun demo() {
log("some message")
someObject.inspect()
}
}
Shows:
16:40:55.076 D .(LogSugarDemo.kt:8): 0.002s demo() 🍬 some message
16:40:55.077 D .(LogSugarDemo.kt:9): 0.002s demo() 🍬 SomeObject(prop1=something, prop2=42)
See LogSugarDemo.kt
NOTE: Android logcat supports color but Android Studio's logcat view does not. 😢
Author: Jeff Wright