Logging with Retrofit 2
Retrofit has been updated to 2.0 version.
It’s a major change in the one of the most popular library for Android platform.</br> A lot of things have been changed out there but in this blog post I want to cover how to setup logging properly.
Retrofit 1.x - old way
In Retrofit 1.x we just call:
Retrofit 2.x - new way
In Retrofit 2 you should use HttpLoggingInterceptor.
Add dependency to
Retrofit object like follow:
RetrofitAdapter doesn’t exsist any longer, we have
Retrofit class instead.
The big change is that OkHttp is required now and set as dependency for Retrofit.
The instance of
OkHttpClient is the place where you should set up logging.
Retrofit has a dependency to OkHttp version 2.5.0, but I’ve tested it with LoggingIntenceptor version 2.6.0 and it works well.
It should print logs similar to the old ones from Retrofit 1.x.
Hope it helps you :)
See this post on my personal blog.