3

可能是一个新手问题,但我想知道我实际上在哪里捕获日志猫中的日志。是否有一个特定的地方我放了一个日志,一个特殊的正则表达式使用等等。这就是我的拦截器的样子:

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();

这是一个 api 调用,其中 body 为空

 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) {

            }
        });
4

1 回答 1

4

我这样使用:

    // 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);
于 2016-02-06T02:02:33.653 回答