Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Retrofit log does not show

Retrofit does not print log. Log level set to verbose. Tried HttpLoggingInterceptor too.

using these gradles

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'

Code

OkHttpClient httpClient = new OkHttpClient();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.newBuilder().connectTimeout(6, TimeUnit.MINUTES)
                .readTimeout(6, TimeUnit.MINUTES)
                .writeTimeout(6, TimeUnit.MINUTES)
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request original = chain.request();
                        Request.Builder requestBuilder = original.newBuilder()
                                .header("Content-Type", "application/json")
                                .header("Authorization", "aDRF@F#JG_a34-n3d")
                                .method(original.method(), original.body());
                        Request request = requestBuilder.build();
                        return chain.proceed(request);
                    }
                })
    .addInterceptor(httpLoggingInterceptor);


return httpClient;
like image 260
Harish Gyanani Avatar asked Aug 12 '16 13:08

Harish Gyanani


2 Answers

In some cases you need to allow extended logs on certain physical android devices. This can be done in developers menu in the android phone settings.

like image 147
Fedir Petryk Avatar answered Sep 25 '22 14:09

Fedir Petryk


On some devices (emulator or real Android ones) logging is by default disabled. You need to enable this option to see the logs. Tried this with Meizu M3s.

  1. Go to Developer Options.

  2. Find Performance optimization.

  3. Find Advanced logging.

  4. Allow all.

Please note that for different devices the steps might be slightly different.

enter image description here enter image description here

like image 39
Azizjon Kholmatov Avatar answered Sep 22 '22 14:09

Azizjon Kholmatov