【问题标题】:RxJava2 with Retrofit2-unable to get logs using HttpLoggingInterceptor带有 Retrofit2 的 RxJava2 - 无法使用 HttpLoggingInterceptor 获取日志
【发布时间】:2018-10-25 06:25:40
【问题描述】:

我已将 RxJava2 与 Retrofit2 集成,但无法使用 HttpLoggingInterceptor 获取 api 调用日志。

我正在使用以下依赖项-

compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.2'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'

并使用以下代码

public class RxJavaRetofit {
    private  ApiMethods api;
    public RxJavaRetofit() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(AppUrls.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(client)
                .build();

          api = retrofit.create(ApiMethods.class);

  }

   public void getSocialFeed(Context context, SocialRequest socialRequest, final mevorun.mevolife.com.mevorun.listeners.onSocialServiceResponseHandler onServiceResponseHandler) {
       Utils.showDialog(context);
       api.getSocialData(socialRequest).subscribeOn(Schedulers.io())
               .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Social>() {
           @Override
           public void onSubscribe(Disposable d) {


           }

           @Override
           public void onNext(Social value) {
               try {
                   onServiceResponseHandler.onServerResponse(value.getResponse(),"Feed");
                   Utils.hideDialog();
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }

           @Override
           public void onError(Throwable e) {


           }

           @Override
           public void onComplete() {

               Utils.hideDialog();

           }


       });
   }

在我的 Logcat 中,我选择了调试并搜索 HttpLoggingInterceptor,但没有该关键字的日志。我也尝试了 Verbose,但它没有显示 api 调用的日志。如何获取我的 api 调用的日志?

【问题讨论】:

  • 你的方法RxJavaRetofit() 的返回类型在哪里??
  • @HemantParmar 它是一个构造函数
  • 您是否尝试在日志中搜索OkHttp
  • @FredThanks..with OkHttp 我得到了日志..你可以把它作为答案

标签: android debugging retrofit retrofit2 rx-java2


【解决方案1】:

这几乎是一个评论而不是真正的答案。

您的代码一切正常。拦截器使用标签OkHttp 记录日志。搜索它应该会产生您正在寻找的日志。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多