我正在尝试摆脱日志中的垃圾,例如
当我收到一张图片时
所以我试图重写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()是否足够便宜,可以像这样使用它,但是可以达到目标