PrettyLogger is a handy logger for Okhttp and Ktor.
Add the following dependency to get a library into your build:
implementation 'com.github.CesPaul.PrettyLogger:okhttp:0.1.3'
or
implementation("com.github.CesPaul.PrettyLogger:okhttp:0.1.3")
implementation 'com.github.CesPaul.PrettyLogger:ktor:0.1.3'
or
implementation("com.github.CesPaul.PrettyLogger:ktor:0.1.3")
val prettyLogger by lazy {
PrettyLogger {
Log.d("TAG Okhttp", it)
}
}
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor(prettyLogger).setLevel(HttpLoggingInterceptor.Level.BODY))
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build()
val client = HttpClient(Android) {
install(Logging) {
level = LogLevel.ALL
val prettyLogger = PrettyLogger { Log.d("TAG Ktor", it) }
logger = prettyLogger
}
}