Skip to content

Commit

Permalink
[MOD/#5] Interceptor Log 기반 -> Timber 기반 변경 및 출력 형식 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Dec 28, 2023
1 parent 6efb735 commit 4456f4e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/src/main/java/com/going/going/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import retrofit2.Converter
import retrofit2.Retrofit
import timber.log.Timber
import javax.inject.Singleton

@Module
Expand All @@ -34,7 +36,19 @@ object RetrofitModule {

@Provides
@Singleton
fun provideHttpLoggingInterceptor(): Interceptor = HttpLoggingInterceptor().apply {
fun provideHttpLoggingInterceptor(): Interceptor = HttpLoggingInterceptor { message ->
when {
message.isJsonObject() ->
Timber.tag("okhttp").d(JSONObject(message).toString(4))

message.isJsonArray() ->
Timber.tag("okhttp").d(JSONObject(message).toString(4))

else -> {
Timber.tag("okhttp").d("CONNECTION INFO -> $message")
}
}
}.apply {
level = HttpLoggingInterceptor.Level.BODY
}

Expand Down

0 comments on commit 4456f4e

Please sign in to comment.