Created
January 3, 2020 15:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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