Logging

预计阅读时间: 1 分钟

This feature adds multiplatform logging for HTTP calls.

本特性在构件 io.ktor:ktor-client-logging:$ktor_version 中的 io.ktor.client.features.logging.Logging 类中定义
dependencies { implementation "io.ktor:ktor-client-logging:$ktor_version" }
dependencies { implementation("io.ktor:ktor-client-logging:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-client-logging</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>
dependencies { implementation "io.ktor:ktor-client-logging-jvm:$ktor_version" }
dependencies { implementation("io.ktor:ktor-client-logging-jvm:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-client-logging-jvm</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>
dependencies { implementation "io.ktor:ktor-client-logging-native:$ktor_version" }
dependencies { implementation("io.ktor:ktor-client-logging-native:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-client-logging-native</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>
dependencies { implementation "io.ktor:ktor-client-logging-js:$ktor_version" }
dependencies { implementation("io.ktor:ktor-client-logging-js:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-client-logging-js</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>

Installation

val client = HttpClient() {
    install(Logging) {
        logger = Logger.DEFAULT
        level = LogLevel.HEADERS
    }
}

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.