相关疑难解决方法(0)

使 HttpLoggingInterceptor 不记录图像

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

*?$?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)

如何在我的项目中禁用图像记录?

logging android retrofit okhttp

13
推荐指数
1
解决办法
1464
查看次数

标签 统计

android ×1

logging ×1

okhttp ×1

retrofit ×1