Kotlin multiplatform HTTP client logging plugin for LinuxX64 target that provides comprehensive request and response logging capabilities.
—
Comprehensive configuration options for the Ktor Client Logging plugin, including installation, level settings, filtering, and header sanitization.
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
}
}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)
}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") }
}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")
}
}/**
* General format for logging requests and responses
* Default: LoggingFormat.Default
*/
var format: LoggingFormat/**
* Logger instance to use for output
* Default: Logger.DEFAULT (platform-specific)
*/
var logger: Logger/**
* Logging level specifying what information to log
* Default: LogLevel.HEADERS
*/
var level: LogLevelInstall with Tessl CLI
npx tessl i tessl/maven-io-ktor--ktor-client-logging-linuxx64