Logging

This feature adds multiplatform logging for HTTP calls.

This feature is defined in the class io.ktor.client.features.logging.Logging in the artifact io.ktor:ktor-client-logging:$ktor_version.

  1. dependencies {
  2. implementation "io.ktor:ktor-client-logging:$ktor_version"
  3. }
  1. dependencies {
  2. implementation("io.ktor:ktor-client-logging:$ktor_version")
  3. }
  1. <project>
  2. ...
  3. <dependencies>
  4. <dependency>
  5. <groupId>io.ktor</groupId>
  6. <artifactId>ktor-client-logging</artifactId>
  7. <version>${ktor.version}</version>
  8. <scope>compile</scope>
  9. </dependency>
  10. </dependencies>
  11. </project>
  1. dependencies {
  2. implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
  3. }
  1. dependencies {
  2. implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
  3. }
  1. <project>
  2. ...
  3. <dependencies>
  4. <dependency>
  5. <groupId>io.ktor</groupId>
  6. <artifactId>ktor-client-logging-jvm</artifactId>
  7. <version>${ktor.version}</version>
  8. <scope>compile</scope>
  9. </dependency>
  10. </dependencies>
  11. </project>
  1. dependencies {
  2. implementation "io.ktor:ktor-client-logging-native:$ktor_version"
  3. }
  1. dependencies {
  2. implementation("io.ktor:ktor-client-logging-native:$ktor_version")
  3. }
  1. <project>
  2. ...
  3. <dependencies>
  4. <dependency>
  5. <groupId>io.ktor</groupId>
  6. <artifactId>ktor-client-logging-native</artifactId>
  7. <version>${ktor.version}</version>
  8. <scope>compile</scope>
  9. </dependency>
  10. </dependencies>
  11. </project>
  1. dependencies {
  2. implementation "io.ktor:ktor-client-logging-js:$ktor_version"
  3. }
  1. dependencies {
  2. implementation("io.ktor:ktor-client-logging-js:$ktor_version")
  3. }
  1. <project>
  2. ...
  3. <dependencies>
  4. <dependency>
  5. <groupId>io.ktor</groupId>
  6. <artifactId>ktor-client-logging-js</artifactId>
  7. <version>${ktor.version}</version>
  8. <scope>compile</scope>
  9. </dependency>
  10. </dependencies>
  11. </project>

Installation

  1. val client = HttpClient() {
  2. install(Logging) {
  3. logger = Logger.DEFAULT
  4. level = LogLevel.HEADERS
  5. }
  6. }

To use this feature, you need to include io.ktor:ktor-client-logging-jvm artifact on the JVM and ktor-client-logging-native on iOS.