Created
December 28, 2016 05:43
-
-
Save javadghane/3963b8c72a3d049de19b6c64a4f9e947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to log all retrofit event? | |
Here a way that use Logging Interceptor from okhttp |
add interceptor to your retrofit instance:
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();```
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl(baseAddress)
.addConverterFactory(GsonConverterFactory.create())
.client(client) //add here
.build();
now all network log has been auto generated at logcat by this tag: 'OkHttp'
example:
D/dalvikvm: threadid=12 (OkHttp Dispatcher): calling run()
D/OkHttp: --> POST https://api.test.com/file.php http/1.1
D/OkHttp: Content-Type: application/x-www-form-urlencoded
D/OkHttp: Content-Length: 136
D/OkHttp: op=login&username=john&password=123
D/OkHttp: --> END POST (136-byte body)
D/dalvikvm: threadid=13 (OkHttp ConnectionPool): calling run()
D/dalvikvm: threadid=14 (OkHttp Dispatcher): calling run()
D/dalvikvm: threadid=16 (OkHttp ConnectionPool): calling run()
D/OkHttp: <-- HTTP FAILED: java.net.SocketTimeoutException: failed to connect to https://api.test.com/file.php (port 443) after 10000ms
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add Logging Interceptor library:
compile 'com.squareup.okhttp3:logging-interceptor:find last version here'
like that: