I'm looking to replace
private static final Logger log = Logger.getLogger(MyClass.class);
with something that is a little less verbose and more idiomatic then
class MyClass {
companion object {
val log = LoggerFactory.getLogger(MyClass::class.java)
}
fun usage() {
log.debug("Success")
}
}
Bonus points for not having to delcare it in every class.
I tried:
interface HasLogger {
val log: Logger
get() = LoggerFactory.getLogger(this.javaClass)
}
But this results in a getLogger() call for every usage (inacceptable) also returns a logger for a subtype (not the one where it was declared).