Kotlin 多平台移动 ktor 日志记录不在 logcat 中显示请求参数

ani*_*lst 1 ktor kotlin-multiplatform

我正在尝试使用 ktor 日志记录查看 httpRequest 参数、标头、响应等的日志,但我在 logcat 中看不到任何日志:(

代码块如下所示:

private val httpClient = HttpClient {
    install(ContentNegotiation) {
        json(
            Json {
                prettyPrint = true
                ignoreUnknownKeys = true
                useAlternativeNames = false
            }
        )

        install(Logging) {
            logger = Logger.DEFAULT
            level = LogLevel.ALL
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

你有什么建议吗 ?

** 使用库:

val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
                implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
                implementation("io.ktor:ktor-client-logging:$ktorVersion")
            }
        }
Run Code Online (Sandbox Code Playgroud)

Ale*_*man 5

如果您想在 Logcat 中查看日志消息,Logger请通过将日志记录委托给Log.d()方法来实现该类:

val client = HttpClient {
    install(Logging) {
        logger = object : Logger {
            override fun log(message: String) {
                Log.d("HTTP call", message)
            }
        }
        level = LogLevel.ALL
    }
}
Run Code Online (Sandbox Code Playgroud)