Extensible emoji powered logger of anything. Written in Kotlin for the lols.
This repository is hosted via jitpack since it's by far the easiest delivery method while also being pretty transparent to the developer.
Make sure you have added jitpack to the list of your repositories:
maven("https://jitpack.io")
Then simply add the emojilog
dependency
dependencies {
compile("com.github.vishna:emojilog:master-SNAPSHOT")
}
import dev.vishna.emojilog.std.defaultLogger // default logger
import dev.vishna.emojilog.android.* // predefined "android" like extensions
val log = defaultLogger()
log.info.."Hello world!" // prints: โน๏ธ Hello world!
log.error..IllegalStateException("Whoops!") // prints: ๐ฅ Whoops!
log.wtf..IllegalStateException("๐ฉ hit the fan") // prints: ๐ฅ๐ฅ๐ฅ ๐ฉ hit the fan!
val Log.shrug
get() = { "๐คท" } lvl "shrug"
NOTE: "shrug"
here is a key by which this extension will be cached by the Log
instance
If you would want to do some "extra something" with the output e.g. style the color of the text, you can pass extra parameter of Any
type as a pair
val Log.fail
get() = { "โ" to 0xFF0000 } lvl "fail"
NOTE: This won't magically create colored text for you, you will need to handle this in your own, custom logger.
{Using closure} to avoid evaluating expression whenever the getter is getting called ๐
Here's how you could integrate emojilog in your Android App
Log { level, any ->
val throwable = any as? Throwable
with(level.log) {
when (level) {
verbose -> android.util.Log.v(level.value, "$any")
debug -> android.util.Log.i(level.value, "$any")
info -> android.util.Log.i(level.value, "$any")
warn -> android.util.Log.w(level.value, "$any", throwable)
error -> android.util.Log.e(level.value, "$any", throwable)
wtf -> android.util.Log.wtf(level.value, "$any", throwable)
else -> android.util.Log.d(level.value, "$any")
}
}
}
...if only Android's logcat supported emojis ๐ญ
Please check out tests ๐ LogTest
While creating this library I wasn't aware of Emoji-Log by ahmadawais. The scope of that project is different and focuses on formatting of git commit messages while this one is meant to be logger for simple pet projects written in Kotlin. Anyway, as a tribute to his project, I added git extensions and some tests for it.
๐บ Cheers!