android - Logging in Retrofit 2.0 -
previous version of retrofit uses restadapter , has provision of enabling logs. why feature removed in retrofit 2.0?
to enable log, have do..
retrofit retrofit = new retrofit.builder() .baseurl(base_url) .addconverterfactory(gsonconverterfactory.create()) .build(); /** handles log */ retrofit.client().interceptors().add(new logginginterceptor()); class logginginterceptor implements interceptor { @override public response intercept(interceptor.chain chain) throws ioexception { request request = chain.request(); long t1 = system.nanotime(); logger.d(string.format("sending request %s on %s%n%s", request.url(), chain.connection(), request.headers())); response response = chain.proceed(request); long t2 = system.nanotime(); logger.d(string.format("received response %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers())); // logger.d(""+new string(response.body().bytes())); return response; }
this solution this? previous provision handy...
intention of retrofit perform type safe de/serialization. has dropped features should performed http client, logging.
reasonably, http client should logging responses received rather retrofit. question broad, guys square should add more.
Comments
Post a Comment