Skip to content

Instantly share code, notes, and snippets.

@nisrulz
Created April 14, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisrulz/ad5642b1ea70d3232d782560e761bb1c to your computer and use it in GitHub Desktop.
Save nisrulz/ad5642b1ea70d3232d782560e761bb1c to your computer and use it in GitHub Desktop.
Extension function to get the classname as log tag
// Extension function to get the classname as log tag
val Any.TAG: String
get() {
return if (!javaClass.isAnonymousClass) {
val name = javaClass.simpleName
if (name.length <= 23) name else name.substring(0, 23)// first 23 chars
} else {
val name = javaClass.name
if (name.length <= 23) name else name.substring(name.length - 23, name.length)// last 23 chars
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment