Kotlin multiplatform HTTP client logging plugin for LinuxX64 target that provides comprehensive request and response logging capabilities.
—
Multiple output format options for HTTP request/response logging, including Ktor's default format and OkHttp-compatible formatting for tool integration.
Defines the output formatting style for logged HTTP requests and responses.
/**
* Output formatting options for HTTP logging
*/
enum class LoggingFormat {
/** Standard Ktor logging format with detailed request/response structure */
Default,
/**
* OkHttp-compatible logging format for tool integration
* Writes only application-level logs because low-level HTTP communication
* is hidden within engine implementations
*/
OkHttp
}Usage Examples:
import io.ktor.client.*
import io.ktor.client.plugins.logging.*
// Use default Ktor format
val client = HttpClient {
install(Logging) {
format = LoggingFormat.Default // Default value
level = LogLevel.ALL
}
}
// Use OkHttp-compatible format
val client = HttpClient {
install(Logging) {
format = LoggingFormat.OkHttp
level = LogLevel.ALL
}
}The standard Ktor logging format provides structured, detailed output with clear separation between request and response sections.
Request Format Example:
REQUEST: https://api.example.com/users
METHOD: POST
COMMON HEADERS
-> Content-Type: application/json
-> Authorization: ***
CONTENT HEADERS
-> Content-Length: 156
BODY Content-Type: application/json
BODY START
{"name": "John Doe", "email": "john@example.com"}
BODY ENDResponse Format Example:
RESPONSE: 201 Created
METHOD: POST
FROM: https://api.example.com/users
COMMON HEADERS
-> Content-Type: application/json
-> Location: /users/123
BODY Content-Type: application/json
BODY START
{"id": 123, "name": "John Doe", "email": "john@example.com"}
BODY ENDDefault Format Features:
-> prefixOkHttp-compatible format mimics the popular OkHttp logging interceptor output for consistency with existing tools and workflows.
Request Format Example:
--> POST https://api.example.com/users
Content-Type: application/json
Authorization: ██
Content-Length: 156
{"name": "John Doe", "email": "john@example.com"}
--> END POST (156-byte body)Response Format Example:
<-- 201 Created https://api.example.com/users (245ms)
Content-Type: application/json
Location: /users/123
{"id": 123, "name": "John Doe", "email": "john@example.com"}
<-- END HTTP (245ms, 89-byte body)OkHttp Format Features:
--> and <--)| Feature | Default Format | OkHttp Format |
|---|---|---|
| Readability | Highly structured, verbose | Compact, tool-friendly |
| Tool Integration | Ktor-specific | OkHttp-compatible |
| Header Display | Prefixed with -> | Plain format |
| Timing Info | Separate timing logs | Inline with response |
| Body Handling | BODY START/END markers | Inline with size info |
| Binary Detection | Detailed detection info | Simple omission notice |
| Use Cases | Development, debugging | CI/CD, log analysis tools |
Both formats provide intelligent content handling:
// Both formats detect and handle binary content
--> POST /upload (binary 2048-byte body omitted) // OkHttp format
BODY END (binary body omitted) // Default format// Compressed content handling
--> POST /data (encoded 1024-byte body omitted) // OkHttp format
BODY END (encoded body omitted) // Default format// Streaming content detection
<-- 200 OK /events (streaming) // OkHttp format
RESPONSE: 200 OK (streaming response) // Default format// Verbose logging for development
val devClient = HttpClient {
install(Logging) {
format = LoggingFormat.Default
level = LogLevel.ALL
logger = Logger.SIMPLE
}
}// Tool-friendly logging for automated systems
val ciClient = HttpClient {
install(Logging) {
format = LoggingFormat.OkHttp
level = LogLevel.HEADERS
logger = Logger.DEFAULT
}
}// Minimal logging for production
val prodClient = HttpClient {
install(Logging) {
format = LoggingFormat.OkHttp
level = LogLevel.INFO
logger = Logger.DEFAULT
// Filter sensitive endpoints
filter { request ->
!request.url.pathSegments.contains("auth")
}
}
}Install with Tessl CLI
npx tessl i tessl/maven-io-ktor--ktor-client-logging-linuxx64