Retrofit2 HttpLoggingInterceptor Logcat

烂漫一生 提交于 2019-12-10 21:44:37

问题


Probably a novice question but I'm wondering where I actually catch the logs in log cat. Is there a particular place I put a log, a special regex to use etc. This is what my interceptor looks like:

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okClient = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        // Retrofit setup


        Retrofit client = new retrofit2.Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okClient)
                .build();

And here is an api call where the body is null

 retrofit2.Call<GeneralTokenResponse> generalTokenResponseCall = ApiInterface.getGeneralAccessToken(ApiGeneral.API_VERSION);
        generalTokenResponseCall.enqueue(new retrofit2.Callback<GeneralTokenResponse>() {
            @Override
            public void onResponse(retrofit2.Call<GeneralTokenResponse> call, retrofit2.Response<GeneralTokenResponse> response) {
                Log.d("DEBUG", "body: "+response.body());

            }

            @Override
            public void onFailure(retrofit2.Call<GeneralTokenResponse> call, Throwable t) {

            }
        });

回答1:


I use so:

    // init okhttp 3 logger
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
        @Override public void log(String message) {
            Log.d("MyTAG", "OkHttp: " + message);
        }
    });
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);


来源:https://stackoverflow.com/questions/35235565/retrofit2-httplogginginterceptor-logcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!