我正在构建一个Android应用,该应用使用Retrofit进行网络连接。 这是代码:
private val loggingInterceptor by lazy {
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { message -> Log.d(TAG, message) }).apply {
level = if(BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
}
}
val client = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build()
Retrofit.Builder()
.baseUrl(" https://mybaseurl.com/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
我使用HttpLoggingInterceptor,但是日志太冗长,因为它记录了所有标头。
content-language: en-GB
content-type: application/json
date: Sun, 07 Jul 2019 12:52:36 GMT
p3p: CP="NON CUR OTPi OUR NOR UNI"
transfer-encoding: chunked
cache-control: no-cache,no-store,must-reva
x-powered-by: Servlet/3.0
expires: Thu, 01 Dec 1994 16:00:00 GMT
pragma: no-cache
and more....
如果我切换到LogLevel Basic,则不会得到请求和响应,而只会得到URL。 顺便说一句,看一下HttpLoggingInterceptor代码:
boolean logHeaders = logBody || level == Level.HEADERS;
因此,似乎没有标题就没有记录日志正文的实际方法。
是否有任何骇人听闻的方法或解决方法?