Created
August 29, 2021 21:08
-
-
Save trevorhackman/1660c3542b58742da55d2d68726badee to your computer and use it in GitHub Desktop.
For logging in Android. Use through either companion object inheritance or delegating the implementation of the interface for other cases.
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
interface Tag { | |
val tag: String | |
val log: Tagger.TaggedLogger | |
} | |
open class Tagger(override val tag: String) : Tag { | |
interface TaggedLogger { | |
fun e(message: String) | |
fun w(message: String) | |
fun i(message: String) | |
fun d(message: String) | |
fun v(message: String) | |
} | |
override val log = object : TaggedLogger { | |
override fun e(message: String) { | |
Log.e(tag, message) | |
} | |
override fun w(message: String) { | |
Log.w(tag, message) | |
} | |
override fun i(message: String) { | |
Log.i(tag, message) | |
} | |
override fun d(message: String) { | |
Log.d(tag, message) | |
} | |
override fun v(message: String) { | |
Log.v(tag, message) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment