ロギング

Estimated reading time: 1 minute

マルチプラットフォーム対応済の、HTTP リクエスト時のログ出力処理機能を追加できます。

This feature is defined in the class io.ktor.client.features.logging.Logging in the artifact io.ktor:ktor-client-logging:$ktor_version.
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>

インストール

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

この機能を使う場合、 JVM ならば io.ktor:ktor-client-logging-jvm 、 iOS ならば ktor-client-logging-native を依存ライブラリとして追加する必要があります。