Skip to content

Instantly share code, notes, and snippets.

@gmazzo
Last active February 2, 2018 15:20
Show Gist options
  • Save gmazzo/7b8bd8f1e173a22ed492581e74e5cd76 to your computer and use it in GitHub Desktop.
Save gmazzo/7b8bd8f1e173a22ed492581e74e5cd76 to your computer and use it in GitHub Desktop.
A lightweight Kotlin extension for java.util.logging.Logger simple support
/**
* 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