I want to modify this log helper function to print out coroutine id or name.
@JvmInline
value class MyLogger(private val tag: String) {
fun log(level: Level, e: Throwable? = null, message: String) {
if (isLoggingEnabled(level)) {
val logTime = System.currentTimeMillis()
val messageWithCoroutineInfo = "Running on: [${Thread.currentThread().name}] | $message"
when (level) {
Level.VERBOSE -> Log.v(tag, messageWithCoroutineInfo, e)
Level.DEBUG -> Log.d(tag, messageWithCoroutineInfo, e)
Level.INFO -> Log.i(tag, messageWithCoroutineInfo, e)
Level.WARN -> Log.w(tag, messageWithCoroutineInfo, e)
Level.ERROR -> Log.e(tag, messageWithCoroutineInfo, e)
Level.ASSERT -> Log.wtf(tag, messageWithCoroutineInfo, e)
}
}
}
....
}
private val logger = MYLogger("Navigator")
logger.i { "goTo: $screen; backstack: [${backStack.joinToString()}]" }
In onCreate function:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
System.setProperty("kotlinx.coroutines.debug", if(!BuildTypes.isProduction) "on" else "off")
it can print out the thread name, but it can't print out the coroutine id or name, such as [AWT-EventQueue-0 @coroutine#40], any suggestion?