Skip to content

Instantly share code, notes, and snippets.

@williamokano
Created January 3, 2020 15:29
Show Gist options
  • Save williamokano/c57ee861da340f6e8b792e051a4248ab to your computer and use it in GitHub Desktop.
Save williamokano/c57ee861da340f6e8b792e051a4248ab to your computer and use it in GitHub Desktop.
Simple logger "wrapper" to create loggers and remove the boiler plate of LoggerFactory
fun <T : Any> T.logger(): Logger =
LoggerFactory.getLogger(this::class.java.name.substringBefore("\$Companion"))
class XPTO {
fun info(message: String) {
logger.info(message)
}
companion object {
private val logger = logger()
}
}
fun main() {
val xpto = XPTO()
xpto.info("Hello World")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment