classLoggingInterceptorimplementsInterceptor{@OverridepublicResponseintercept(Interceptor.Chainchain)throwsIOException{Requestrequest=chain.request();longt1=System.nanoTime();logger.info(String.format("Sending request %s on %s%n%s",request.url(),chain.connection(),request.headers()));Responseresponse=chain.proceed(request);longt2=System.nanoTime();logger.info(String.format("Received response for %s in %.1fms%n%s",response.request().url(),(t2-t1)/1e6d,response.headers()));returnresponse;}}
INFO:Sendingrequesthttp://www.publicobject.com/helloworld.txt on nullUser-Agent:OkHttpExampleINFO:Receivedresponseforhttps://publicobject.com/helloworld.txt in 1179.7msServer:nginx/1.4.6(Ubuntu)Content-Type:text/plainContent-Length:1759Connection:keep-alive
INFO:Sendingrequesthttp://www.publicobject.com/helloworld.txt on Connection{www.publicobject.com:80, proxy=DIRECT hostAddress=54.187.32.157 cipherSuite=none protocol=http/1.1}User-Agent:OkHttpExampleHost:www.publicobject.comConnection:Keep-AliveAccept-Encoding:gzipINFO:Receivedresponseforhttp://www.publicobject.com/helloworld.txt in 115.6msServer:nginx/1.4.6(Ubuntu)Content-Type:text/htmlContent-Length:193Connection:keep-aliveLocation:https://publicobject.com/helloworld.txtINFO:Sendingrequesthttps://publicobject.com/helloworld.txt on Connection{publicobject.com:443, proxy=DIRECT hostAddress=54.187.32.157 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1}User-Agent:OkHttpExampleHost:publicobject.comConnection:Keep-AliveAccept-Encoding:gzipINFO:Receivedresponseforhttps://publicobject.com/helloworld.txt in 80.9msServer:nginx/1.4.6(Ubuntu)Content-Type:text/plainContent-Length:1759Connection:keep-alive