wafflestudio / seminar-2021

2021 Rookies 세미나
47 stars 110 forks source link

안드로이드 과제4 Dagger Hilt로 만든 okhttpclient에서 logcat 출력 설정 방법 #668

Closed JuTaK97 closed 2 years ago

JuTaK97 commented 2 years ago

요약

통신이 잘 되고 있는건지 어떤건지 상황을 전혀 모르겠어서 okhttpclient가 logcat에 모든 log를 남기도록 하고 싶습니다.
그런데 Dagger Hilt로 만든 okhttpclient를 어떻게 바꿔야 할 지 모르겠습니다.



상황

seminar 4에서 다뤘던 Dagger Hilt를 사용중인데, 이 때문에 구글링 해서 얻은 방법으로는 해결하지 못하고 있습니다.

    @Provides
    @Singleton
    fun provideHttpClient(sharedPreferences: SharedPreferences): OkHttpClient {
        return OkHttpClient.Builder()
            .addInterceptor { chain: Interceptor.Chain ->
                val newRequest = chain.request().newBuilder().addHeader(
                    "Authorization", "${sharedPreferences.getString("token", "")}"
                ).build()
                chain.proceed(newRequest)
            }
            .build()
    }

여기에 뭔가 추가해야 하는데, 저 코드 자체도 이해하기가 힘들어서 건드리지 못하고 있습니다.



문제 내용

찾아보면 interceptor.level = HttpLoggingInterceptor.Level.Body 로 하는 것 같은데, 위의 코드에서는 interceptor가 따로 val로 분리되어 있지가 않아서 어떻게 해야 할지 모르겠네요.



veldic commented 2 years ago

Assignment 3 Skeleton Code https://github.com/wafflestudio/19.5-rookies/blob/7fc3cca4152ef8da772d87634939fb367875afa2/android/assignment_3/Assignment3Skeleton/app/src/main/java/com/wafflestudio/assignment3skeleton/App.kt#L26-L36 참고하시면 좋을 것 같습니다 ㅎㅎ

JuTaK97 commented 2 years ago

감사합니다!!