gpt4 book ai didi

android - 使 HttpLoggingInterceptor 不记录图像

转载 作者:太空狗 更新时间:2023-10-29 13:51:36 25 4
gpt4 key购买 nike

我正在尝试清除日志中的垃圾,例如

*�$ʞ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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com