【发布时间】:2019-10-20 18:23:57
【问题描述】:
当我使用 Retrofit 时,我可以轻松地创建日志拦截器以在 logcat 上查看带有正文和标头的调用:
val loggingInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
val httpClient = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
然后
val retrofit = retrofit2.Retrofit.Builder()
.client(httpClient.build())
现在,we switched to Ktor 我不知道 不知道怎么弄的
- 使用
addInterceptor()? - 对于 [
install(CallLogging)][2] 没有任何反应..
有什么建议或例子吗?
[2] 来源:
fun Application.main() {
install(CallLogging){
level = Level.TRACE
}
}
【问题讨论】:
-
我在导入 io.ktor.features 时遇到问题什么问题?
-
@TimCastelijns io.ktor.features 来自哪里?显然实现“io.ktor:ktor-features:$ktor_version”对我不起作用
-
它似乎内置于“此功能在类 io.ktor.features.CallLogging 中定义,不需要额外的工件。”尝试省略导入
-
不,这不是问题所在。我只有` implementation "io.ktor:ktor-client-okhttp:$ktor_version"`。所以我添加了:` implementation "io.ktor:ktor-server-netty:$ktor_version"`