LoggingInterceptor.java 915 B

12345678910111213141516171819202122232425262728293031323334
  1. package com.emato.ich.api;
  2. import android.util.Log;
  3. import java.io.IOException;
  4. import okhttp3.Interceptor;
  5. import okhttp3.Request;
  6. import okhttp3.Response;
  7. /**
  8. * okhttp请求响应日志拦截器
  9. * 已废弃
  10. */
  11. public class LoggingInterceptor implements Interceptor {
  12. public static final String TAG = "Http_log";
  13. @Override
  14. public Response intercept(Interceptor.Chain chain) throws IOException {
  15. Request request = chain.request();
  16. long t1 = System.nanoTime();
  17. Log.i(TAG, String.format("Sending request %s on %s%n%s",
  18. request.url(), chain.connection(), request.headers()));
  19. Response response = chain.proceed(request);
  20. long t2 = System.nanoTime();
  21. Log.i(TAG, String.format("Received response for %s in %.1fms%n%s",
  22. response.request().url(), (t2 - t1) / 1e6d, response.headers()));
  23. return response;
  24. }
  25. }