Android okhttp日志未打印
我正在使用此方法改装构建api客户端:Android okhttp日志未打印,android,okhttp,Android,Okhttp,我正在使用此方法改装构建api客户端: private fun createNewApiClient(authRefreshClient: AuthRefreshClient, preferencesInteractor: PreferencesInteractor): ApiClient { val loggingInterceptor = HttpLoggingInterceptor(PrettyLogge
private fun createNewApiClient(authRefreshClient: AuthRefreshClient,
preferencesInteractor: PreferencesInteractor): ApiClient {
val loggingInterceptor = HttpLoggingInterceptor(PrettyLogger())
loggingInterceptor.level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
val okHttpClient = createHttpClientBuilder()
.addInterceptor(loggingInterceptor)
.build()
return Retrofit.Builder()
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.baseUrl(Interactors.apiEndpoint)
.build()
.create(ApiClient::class.java)
}
在生成的BuildConfig文件中,Debug设置为true:
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
}
我可以确认我与该客户的通话正在进行中,因为我在RX订阅的可丢弃部分中添加了很多声明:
Interactors.api.apiClient.getUserByEmail(email).
.subscribe({
Log.d("Email exists")
//Success
}, {
Log.e("Call is failing")
}
})
但是请求的主体没有显示在我的日志语句中。okhttp没有显示任何内容。我的okhttp实现有什么问题吗?尝试将您的
PrettyLogger()
替换为HttpLoggingInterceptor
因此,替换你的:
val loggingInterceptor = HttpLoggingInterceptor(PrettyLogger())
关于:
val loggingInterceptor = HttpLoggingInterceptor()
您确定在
BuildConfig
中有true
值吗?编译后是否进入该类?该类由编译过程生成。我还删除了if语句,并在所有情况下将日志记录级别设置为full,但它仍然不起作用?尝试使用库中的HttpLoggingInterceptor.Logger。这就是诀窍。非常感谢。