Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrofit request, response Body가 logcat 에 출력이 되지 않는 이슈 #118

Closed
easyhooon opened this issue Aug 29, 2023 · 1 comment
Assignees
Labels
feature tasks related to feature development

Comments

@easyhooon
Copy link
Collaborator

easyhooon commented Aug 29, 2023

private const val MaxTimeoutMillis = 3000L

private val json = Json {
  encodeDefaults = true
  ignoreUnknownKeys = true
  prettyPrint = true
  isLenient = true
}

private val jsonRule = Json { json }

@Module
@InstallIn(SingletonComponent::class)
internal object NetworkModule {

  @Singleton
  @Provides
  fun provideRetrofitHttpClient(dataStoreProvider: DataStoreProvider): Retrofit {
    val contentType = "application/json".toMediaType()
    val httpClient = OkHttpClient.Builder()
      .connectTimeout(MaxTimeoutMillis, TimeUnit.MILLISECONDS)
      .addInterceptor { chain: Interceptor.Chain ->
        val request = chain.request().newBuilder()
          .addHeader("Content-Type", "application/json")
          .addHeader("X-GUEST-KEY", runBlocking { dataStoreProvider.getGuestLoginToken() })
          .build()
        chain.proceed(request)
      }
      .addInterceptor(
        HttpLoggingInterceptor { message ->
          Timber.tag("HttpClient").d(message)
        }.setLevel(HttpLoggingInterceptor.Level.BODY),
      )
      .build()

    return Retrofit.Builder()
      .baseUrl(BuildConfig.SERVER_BASE_URL)
      .client(httpClient)
      .addConverterFactory(jsonRule.asConverterFactory(contentType))
      .build()
  }
}

다음과 같이 setLevel(HttpLoggingInterceptor.Level.BODY), 로 설정을 하였으나 request, response 의 body가 로그캣에 출력되지 않고 , request의 endpoint 와 response 의 httpCode 만 출력되는 문제

@easyhooon easyhooon changed the title Retrofit request, response Body log 가 logcat 에 출력이 되지 않는 이슈 Retrofit request, response Body가 logcat 에 출력이 되지 않는 이슈 Aug 29, 2023
@easyhooon easyhooon self-assigned this Aug 29, 2023
@easyhooon easyhooon added the feature tasks related to feature development label Aug 29, 2023
@easyhooon
Copy link
Collaborator Author

#119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature tasks related to feature development
Projects
None yet
Development

No branches or pull requests

1 participant