我正在尝试清除日志中的垃圾,例如
*�$ʞx���J/
当我收到一张图片时
所以我尝试重写 HttpLoggingInterceptor intercept(),以检测响应中是否有 Content-Type => image/jpeg header ,但是 HttpLoggingInterceptor 是最终的,所以我不能扩展它:(
RetrofitModule 中的代码:
OkHttpClient provideOkHttpClient(Context context, Application app, Preferences preferences) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.HEADERS);
Cache cache = new Cache(app.getCacheDir(), cacheSize);
return new OkHttpClient.Builder()
.addNetworkInterceptor(new OkHttpInterceptor(context, preferences))
.addInterceptor(loggingInterceptor)
.cache(cache)
.build();
}
如何在我的项目中禁用图像记录?
最佳答案
所以,既然没人知道答案,我就发明我自己的自行车:
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
if(!message.contains("�")){
Timber.d(message);
}
}
});
不太确定 String.contains() 是否足够便宜以像这样使用它,但目标已达到
关于android - 使 HttpLoggingInterceptor 不记录图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340230/