When answering a simple stack overflow question, I...
# announcements
a
When answering a simple stack overflow question, I realize that the options available to a Kotlin programmer are very large for how to construct and use libraries. http://stackoverflow.com/a/34462577/3679676 … and there are a few cute tricks in there that not everyone is aware of. Here is a way to cheat and make a simple instance of
Lazy
to act as a delegate for a logger for the enclosing class:
Copy code
public fun <R : Any> R.logger(): Lazy<Logger> {
    return lazy { Logger.getLogger(unwrapCompanionClass(this.javaClass).name) }
}
Then use this function as a delegate:
Copy code
class Something {
    val LOG by logger()  // really calling extension seen as Something.logger()

    fun foo() {
        <http://LOG.info|LOG.info>("Hello from Something")
    }
}
more in the SO link above. Add a comment if you think differently about what is more common or not, and if there are variations missing that are useful.