gpt4 book ai didi

android - Retrofit2 HttpLoggingInterceptor Logcat

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:27 43 4
gpt4 key购买 nike

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

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

这是一个 body 为空的 api 调用

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

}
});

最佳答案

我是这样用的:

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

关于android - Retrofit2 HttpLoggingInterceptor Logcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35235565/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com