Last active
October 25, 2018 11:41
-
-
Save nieldw/55bdca86c685914c2d26f75d7637a287 to your computer and use it in GitHub Desktop.
Kotlin Top Level Function loggers
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
package com.example.nieldw | |
import org.apache.logging.log4j.LogManager | |
import org.apache.logging.log4j.Logger | |
import org.junit.jupiter.api.Test | |
fun logger(lambda: () -> Unit): Lazy<Logger> = lazy { LogManager.getLogger(getClassName(lambda.javaClass)) } | |
private fun <T : Any> getClassName(clazz: Class<T>): String = clazz.name.replace(Regex("""\$.*$"""), "") | |
val topLog by logger { } | |
fun doLogging() { | |
topLog.info("THIS IS IT") | |
} | |
class TopLevelLoggingTest { | |
@Test | |
fun `What is the javaClass?`() { | |
doLogging() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment