Im Versuch, alle Anfragen zu protokollieren (mit einem Netzwerk-Interceptor) mit refrofit2, Kotlin und Logging-Abfangjäger:HttpLoggingInterceptor Anmeldung nicht mit Retrofit 2
- Nachrüstung: "2.0.2"
- okhttp3: " 3.2.0"
- com.squareup.okhttp3: Logging-Interceptor 3.2.0
wie:
val interceptor = HttpLoggingInterceptor()
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(interceptor) // same for .addInterceptor(...)
.connectTimeout(30, TimeUnit.SECONDS) //Backend is really slow
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build()
sRestAdapter = Retrofit.Builder()
.client(okHttpClient)
.baseUrl(if (host.endsWith("/")) host else "$host/")
.addConverterFactory(GsonConverterFactory.create(gson()))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()
Es bedrucken:
D/OkHttp: --> GET url...
D/OkHttp: --> END GET
Was geschieht?
--------------- EDIT --------
Fehler Anfragen auf Hauptthread tun nicht durch den Logger zeigt, so vorsichtig sein.
http://stackoverflow.com/questions/33141407/logging-in-retrofit-2-0/38890345#38890345 –