or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-config.mdconfiguration.mdindex.mdlevels-formats.mdloggers.mdplatform-features.md
tile.json

tessl/maven-io-ktor--ktor-client-logging-jvm

HTTP client logging plugin for Ktor client framework with configurable logging formats, levels, and platform-specific logger integrations

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.ktor/ktor-client-logging-jvm@3.2.x

To install, run

npx @tessl/cli install tessl/maven-io-ktor--ktor-client-logging-jvm@3.2.0

index.mddocs/

Ktor Client Logging Plugin

Ktor Client Logging is a powerful plugin that provides comprehensive HTTP request and response logging capabilities for Ktor client applications. It offers configurable logging formats (Default and OkHttp-compatible), multiple log levels, support for custom loggers with platform-specific optimizations, header sanitization for security, and MDC context propagation for coroutines.

Package Information

  • Package Name: io.ktor:ktor-client-logging-jvm
  • Package Type: maven
  • Language: Kotlin
  • Installation:
    implementation("io.ktor:ktor-client-logging-jvm:3.2.0")

Core Imports

import io.ktor.client.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.request.*
import io.ktor.http.*

Basic Usage

import io.ktor.client.*
import io.ktor.client.plugins.logging.*

val client = HttpClient {
    install(Logging) {
        logger = Logger.DEFAULT
        level = LogLevel.ALL
        format = LoggingFormat.Default
    }
}

Architecture

Ktor Client Logging is built around several key components:

  • Core Plugin: The main Logging plugin that intercepts HTTP calls and coordinates logging
  • Configuration System: LoggingConfig class providing fluent DSL for plugin setup
  • Logger Interface: Pluggable logger system with platform-specific implementations
  • Log Levels: Granular control over what information gets logged (NONE, INFO, HEADERS, BODY, ALL)
  • Formatting: Multiple output formats including Default Ktor format and OkHttp-compatible format
  • Header Sanitization: Security features to redact sensitive headers like Authorization
  • Platform Integration: Native integration with SLF4J on JVM, Android Logcat, and console logging on other platforms

Capabilities

Core Logging Plugin

Main plugin installation and configuration functionality. Provides the foundation for all HTTP call logging with extensive customization options.

val Logging: ClientPlugin<LoggingConfig>

fun HttpClientConfig<*>.install(plugin: ClientPlugin<LoggingConfig>, configure: LoggingConfig.() -> Unit = {})

Core Plugin Configuration

Logger Interface and Implementations

Pluggable logger system with platform-specific implementations including SLF4J integration, Android Logcat support, and message length limiting for platforms with log truncation.

interface Logger {
    fun log(message: String)
    
    companion object {
        val DEFAULT: Logger
        val SIMPLE: Logger
        val EMPTY: Logger
        val ANDROID: Logger // JVM only
    }
}

class MessageLengthLimitingLogger(
    private val maxLength: Int = 4000,
    private val minLength: Int = 3000,
    private val delegate: Logger = Logger.DEFAULT
) : Logger {
    override fun log(message: String)
}

Logger Implementations

Log Levels and Formats

Fine-grained control over logging verbosity and output formatting with support for different logging styles and selective information disclosure.

enum class LogLevel(
    val info: Boolean,
    val headers: Boolean,
    val body: Boolean
) {
    ALL(true, true, true),
    HEADERS(true, true, false),
    BODY(true, false, true),
    INFO(true, false, false),
    NONE(false, false, false)
}

enum class LoggingFormat {
    Default,
    OkHttp
}

Levels and Formats

Advanced Configuration Features

Security and filtering capabilities including header sanitization to prevent sensitive data leakage and request filtering for selective logging.

class LoggingConfig {
    var format: LoggingFormat
    var logger: Logger
    var level: LogLevel
    
    fun filter(predicate: (HttpRequestBuilder) -> Boolean)
    fun sanitizeHeader(placeholder: String = "***", predicate: (String) -> Boolean)
    
    internal val filters: MutableList<(HttpRequestBuilder) -> Boolean>
    internal val sanitizedHeaders: MutableList<(String, String) -> String>
}

Advanced Configuration

Platform-Specific Features

MDC context support and platform-optimized logging implementations for different environments including coroutine context propagation.

// JVM only
fun MDCContext(): CoroutineContext.Element

// Platform-specific MDC context implementations
expect fun MDCContext(): CoroutineContext.Element

Platform Features