android,retrofit,okhttp,日志拦截器,使用拦截器Interceptor统一打印请求与响应的json:
https://blog.csdn.net/qq_37043246/article/details/73293421;
public class LoggingInterceptor implements Interceptor {
String TAG = "LoggingInterceptor";
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Log.v(TAG, "request:" + request.toString());
long t1 = System.nanoTime();
okhttp3.Response response = chain.proceed(chain.request());
long t2 = System.nanoTime();
Log.v(TAG, String.format(Locale.getDefault(), "Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers()));
okhttp3.MediaType mediaType = response.body().contentType();
String content = response.body().string();
Log.i(TAG, "response body:" + content);
return response.newBuilder().body(okhttp3.ResponseBody.create(mediaType, content)).build();
} // 下面的span没什么用
}