Hi, simple but nonetheless important question! I'm...
# android
Hi, simple but nonetheless important question! I'm migrating some Java -> Kotlin with a lot of logging going on; How do you guys declare the
string? Currently I'm just declaring it like:
private val tag = AutoDispose::class.java.simpleName!!
If you want to use class name as a tag, you can use extension function. Something like this one: fun Any.debug(message: String) { Log.d(this.javaClass.simpleName, message) }
That does reflection every time you log though. I use an interface I made myself that you implement on a companion object via delegation to a reified function that gets the class tag, and gives you methods like
, etc. Anko Logging also does something similar https://github.com/Kotlin/anko/wiki/Anko-Commons-%E2%80%93-Logging#trait-like-style
@kevinmost Thanks, I didn't think of the class name being accessed via reflection regarding Segeis method but that makes total sense! I found some inspiration here https://github.com/Kotlin/anko/blob/master/anko/library/static/commons/src/Logging.kt (the impl of AnkoLogger, there's a lot of goodies in there regarding building libs)
yup, that's basically how my single-interface logger is built too actually
it works very well
­čÖî 1