Last active
February 2, 2018 15:20
-
-
Save gmazzo/7b8bd8f1e173a22ed492581e74e5cd76 to your computer and use it in GitHub Desktop.
A lightweight Kotlin extension for java.util.logging.Logger simple support
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
/** | |
* A lightweight Kotlin extension for java.util.logging.Logger simple support | |
* | |
* Usage: | |
* | |
* At top level add: | |
* private val log = logger<MyClass>() | |
* | |
* Then on class body: | |
* log.info "Some log" | |
* log.error "Some error" | |
*/ | |
import java.util.logging.Logger | |
import kotlin.reflect.KClass | |
fun logger(name: String): Logger = Logger.getLogger(name) | |
fun <T : Any> logger(clazz: Class<T>) = logger(clazz.name) | |
fun <T : Any> logger(clazz: KClass<T>) = logger(clazz.java) | |
inline fun <reified T : Any> logger() = logger(T::class) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment