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

output-formatting.mddocs/

Output Formatting

Multiple output format options for HTTP request/response logging, including Ktor's default format and OkHttp-compatible formatting for tool integration.

Capabilities

LoggingFormat Enum

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
    }
}

Format Details

Default Format

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 END

Response 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 END

Default Format Features:

  • Clear section headers (REQUEST/RESPONSE, METHOD, HEADERS, BODY)
  • Structured header presentation with -> prefix
  • Separate COMMON HEADERS and CONTENT HEADERS sections
  • Binary content detection and omission
  • Content-Type and body length information
  • Header sanitization with configurable placeholders

OkHttp Format

OkHttp-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:

  • Single-line request/response start indicators (--> and <--)
  • Inline timing information in response headers
  • Compact header presentation (no prefixes)
  • Body size information in end markers
  • Timing details showing request duration
  • Binary and encoded content handling
  • Streaming response detection

Format Comparison

FeatureDefault FormatOkHttp Format
ReadabilityHighly structured, verboseCompact, tool-friendly
Tool IntegrationKtor-specificOkHttp-compatible
Header DisplayPrefixed with ->Plain format
Timing InfoSeparate timing logsInline with response
Body HandlingBODY START/END markersInline with size info
Binary DetectionDetailed detection infoSimple omission notice
Use CasesDevelopment, debuggingCI/CD, log analysis tools

Content Handling

Both formats provide intelligent content handling:

Binary Content Detection

// Both formats detect and handle binary content
--> POST /upload (binary 2048-byte body omitted)  // OkHttp format
BODY END (binary body omitted)                    // Default format

Content Encoding Detection

// Compressed content handling
--> POST /data (encoded 1024-byte body omitted)   // OkHttp format
BODY END (encoded body omitted)                   // Default format

Streaming Response Handling

// Streaming content detection
<-- 200 OK /events (streaming)                    // OkHttp format  
RESPONSE: 200 OK (streaming response)             // Default format

Configuration Examples

Development Setup

// Verbose logging for development
val devClient = HttpClient {
    install(Logging) {
        format = LoggingFormat.Default
        level = LogLevel.ALL
        logger = Logger.SIMPLE
    }
}

CI/CD Integration

// Tool-friendly logging for automated systems
val ciClient = HttpClient {
    install(Logging) {
        format = LoggingFormat.OkHttp
        level = LogLevel.HEADERS
        logger = Logger.DEFAULT
    }
}

Production Monitoring

// 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

docs

configuration.md

index.md

levels-and-control.md

logger-implementations.md

output-formatting.md

tile.json