CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Kotlin multiplatform HTTP client logging plugin for LinuxX64 target that provides comprehensive request and response logging capabilities.

Pending
Overview
Eval results
Files

configuration.mddocs/

Plugin Configuration

Comprehensive configuration options for the Ktor Client Logging plugin, including installation, level settings, filtering, and header sanitization.

Capabilities

Plugin Installation

Install the Logging plugin in HttpClient with optional configuration block.

/**
 * Core logging plugin instance for HttpClient
 */
val Logging: ClientPlugin<LoggingConfig>

/**
 * Extension function to install and configure the Logging plugin
 * @param block Configuration block for LoggingConfig settings
 */
fun HttpClientConfig<*>.Logging(block: LoggingConfig.() -> Unit = {})

Usage Examples:

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

// Basic installation with defaults
val client = HttpClient {
    install(Logging)
}

// Installation with configuration
val client = HttpClient {
    install(Logging) {
        level = LogLevel.HEADERS
        logger = Logger.DEFAULT  
        format = LoggingFormat.Default
    }
}

Configuration Class

Main configuration class providing all logging options and settings.

/**
 * Configuration class for the Logging plugin
 */
@KtorDsl
class LoggingConfig {
    /** General format for logging requests and responses */
    var format: LoggingFormat
    
    /** Logger instance to use for output */
    var logger: Logger
    
    /** Logging level specifying what information to log */
    var level: LogLevel
    
    /** Add filter to log only calls matching predicate */
    fun filter(predicate: (HttpRequestBuilder) -> Boolean)
    
    /** Sanitize sensitive headers to avoid values appearing in logs */
    fun sanitizeHeader(placeholder: String = "***", predicate: (String) -> Boolean)
}

Request Filtering

Filter which HTTP requests get logged based on custom criteria.

/**
 * Add filter to log only calls matching predicate
 * @param predicate Function that returns true for requests that should be logged
 */
fun filter(predicate: (HttpRequestBuilder) -> Boolean)

Usage Examples:

install(Logging) {
    // Log only requests to specific hosts
    filter { request -> 
        request.url.host.contains("api.example.com") 
    }
    
    // Log only GET requests
    filter { request -> 
        request.method == HttpMethod.Get 
    }
    
    // Log requests with specific headers
    filter { request -> 
        request.headers.contains("X-Debug") 
    }
    
    // Multiple filters (ALL must match)
    filter { request -> request.url.host.contains("api") }
    filter { request -> !request.url.pathSegments.contains("health") }
}

Header Sanitization

Sanitize sensitive header values to prevent them from appearing in logs.

/**
 * Sanitize sensitive headers to avoid their values appearing in logs
 * @param placeholder Replacement text for sanitized values (default: "***")
 * @param predicate Function that returns true for headers that should be sanitized
 */
fun sanitizeHeader(placeholder: String = "***", predicate: (String) -> Boolean)

Usage Examples:

install(Logging) {
    // Sanitize Authorization header
    sanitizeHeader { headerName -> 
        headerName == "Authorization" 
    }
    
    // Sanitize multiple sensitive headers with custom placeholder
    sanitizeHeader("███") { headerName ->
        headerName in listOf("Authorization", "Cookie", "X-API-Key")
    }
    
    // Sanitize headers matching pattern
    sanitizeHeader { headerName ->
        headerName.lowercase().contains("secret") ||
        headerName.lowercase().contains("token")
    }
}

Configuration Properties

Format Property

/**
 * General format for logging requests and responses
 * Default: LoggingFormat.Default
 */
var format: LoggingFormat

Logger Property

/**
 * Logger instance to use for output
 * Default: Logger.DEFAULT (platform-specific)
 */
var logger: Logger

Level Property

/**
 * Logging level specifying what information to log
 * Default: LogLevel.HEADERS
 */
var level: LogLevel

Install with Tessl CLI

npx tessl i tessl/maven-io-ktor--ktor-client-logging-linuxx64

docs

configuration.md

index.md

levels-and-control.md

logger-implementations.md

output-formatting.md

tile.json