ktor client does not log request body
See original GitHub issueKtor Version and Engine Used (client or server and name) ver: 1.3.1, 1.3.2 engine: Apache app: client dependencies:
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(platform("io.ktor:ktor-bom:1.3.2"))
implementation("io.ktor:ktor-client-core")
implementation("io.ktor:ktor-client-logging-jvm")
implementation("io.ktor:ktor-client-apache")
implementation("io.ktor:ktor-client-json-jvm")
implementation("org.slf4j:slf4j-simple:1.7.26")
implementation("org.apache.httpcomponents:httpasyncclient:4.1.4")
}
Describe the bug Request body is not logged even with LogLevel.ALL
To Reproduce
package com.example
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.client.features.logging.DEFAULT
import io.ktor.client.features.logging.LogLevel
import io.ktor.client.features.logging.Logger
import io.ktor.client.features.logging.Logging
import io.ktor.client.request.post
import io.ktor.util.KtorExperimentalAPI
import kotlinx.coroutines.runBlocking
@KtorExperimentalAPI
fun main() {
runBlocking {
val client = HttpClient(Apache) {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
client.post<String>("http://localhost:8080") {
body = """{ "test": "testVal" }"""
}
}
}
Expected behavior Request body is in the log
Actual result
[main] INFO io.ktor.client.HttpClient - REQUEST: http://localhost:8080/
[main] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=POST)
[main] INFO io.ktor.client.HttpClient - COMMON HEADERS
[main] INFO io.ktor.client.HttpClient - -> Accept-Charset: UTF-8
[main] INFO io.ktor.client.HttpClient - -> Accept: */*
[main] INFO io.ktor.client.HttpClient - CONTENT HEADERS
[main] INFO io.ktor.client.HttpClient - BODY Content-Type: text/plain; charset=UTF-8
[main] INFO io.ktor.client.HttpClient - RESPONSE: 200
--- remaining response stuff skipped for brevity ---
Issue Analytics
- State:
- Created 4 years ago
- Reactions:17
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to log requests in ktor http client? - kotlin - Stack Overflow
You can achieve this with the Logging feature. First add the dependency: implementation "io.ktor:ktor-client-logging-native:$ktor_version".
Read more >Logging - Ktor
Ktor client provides the capability to log HTTP calls using the Logging plugin. This plugin provides different logger types for different ...
Read more >Call logging - Ktor
You can learn about general logging configuration from the Logging topic. The CallLogging plugin allows you to log incoming client requests.
Read more >Making requests | Ktor
Set the body of a request, for example, a plain text, a data object, or form parameters. These parameters are exposed by the...
Read more >Logging - Ktor
You can also install and configure the CallLogging plugin to log client requests. For the Native server, Ktor provides a logger that prints ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any update on this? We run into the same issue here and seeing the request body would help a lot
Fixed in 1.4.1