本文主要是介绍Retrofit2 打印网络请求日志,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.新建log拦截器
HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BODY;//新建log拦截器HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {@Overridepublic void log(String message) {DebugLog.i("OkHttpClient","OkHttpMessage:"+message);}});loggingInterceptor.setLevel(level);
2.给httpClient.builder添加拦截器:
//定制OkHttpOkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();//OkHttp进行添加拦截器loggingInterceptorhttpClientBuilder.addInterceptor(loggingInterceptor);return httpClientBuilder.build();
这篇关于Retrofit2 打印网络请求日志的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!