Skip to content

Instantly share code, notes, and snippets.

@dakatso
Last active November 15, 2019 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakatso/10f8ab385e9c20cb2b4427952055e8b3 to your computer and use it in GitHub Desktop.
Save dakatso/10f8ab385e9c20cb2b4427952055e8b3 to your computer and use it in GitHub Desktop.
Koltin android log extension
fun klog(@IntRange(from = 2, to = 6) level: Int, message: Any?) {
if (!BuildConfig.DEBUG) return
Throwable().stackTrace[1].run {
val tag = "commontag"
val fullMessage = "($fileName:$lineNumber): $message"
when (level) {
Log.VERBOSE -> Log.v(tag, fullMessage)
Log.DEBUG -> Log.d(tag, fullMessage)
Log.INFO -> Log.i(tag, fullMessage)
Log.WARN -> Log.w(tag, fullMessage)
Log.ERROR -> Log.e(tag, fullMessage)
else -> throw IllegalArgumentException()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment