我正在尝试清除日志中的垃圾,例如
*?$?x???J/
当我收到图像时
因此,我尝试覆盖 HttpLoggingInterceptor 拦截(),以检测响应中是否存在 Content-Type => image/jpeg 标头,但 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();
}
Run Code Online (Sandbox Code Playgroud)
如何在我的项目中禁用图像记录?