diff --git a/app/src/main/java/com/going/going/di/RetrofitModule.kt b/app/src/main/java/com/going/going/di/RetrofitModule.kt index 790a221a..3cb742fe 100644 --- a/app/src/main/java/com/going/going/di/RetrofitModule.kt +++ b/app/src/main/java/com/going/going/di/RetrofitModule.kt @@ -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 @@ -34,14 +36,26 @@ 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 } @Provides @Singleton fun provideOkHttpClient( - loggingInterceptor: Interceptor + loggingInterceptor: Interceptor, ): OkHttpClient = OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build() @@ -56,4 +70,7 @@ object RetrofitModule { .client(client) .addConverterFactory(factory) .build() -} \ No newline at end of file +} + +fun String?.isJsonObject(): Boolean = this?.startsWith("{") == true && this.endsWith("}") +fun String?.isJsonArray(): Boolean = this?.startsWith("[") == true && this.endsWith("]")