Philip Segerfast
09/10/2025, 4:03 PMval client = HttpClient {
plugins.forEach {
install(it)
}
}
We started with the Logger. Our idea was to create a custom plugin that installs the Logger and itself and configures it but we found out that you can't do that with Plugins (or can you?).
The official documentation asks you to just install Logger explicitly in the HttpClientConfig but we want to do this outside of HttpClient.
Is there a common approach on how to do this?
Here's one idea I had:
interface KtorInstallable {
fun HttpClientConfig<*>.install()
}
interface PlatformLogger {
fun logKtor(message: String)
}
class CustomLoggerPlugin(
private val platformLogger: PlatformLogger,
) : KtorInstallable {
override fun HttpClientConfig<*>.install() {
install(Logging) {
logger = object : Logger {
override fun log(message: String) {
platformLogger.logKtor(message)
}
}
}
}
}
class CustomHttpClient(plugins: List<KtorInstallable>) {
val client = HttpClient {
plugins.forEach { plugin ->
plugin.run { install() }
}
}
}
We are quite new to Ktor.
Thank you!!Aleksei Tirman [JB]
09/11/2025, 7:50 AMPhilip Segerfast
09/11/2025, 7:52 AMPhilip Segerfast
09/11/2025, 7:53 AM