0
# Ktor Client Logging
1
2
Ktor Client Logging is a multiplatform HTTP client plugin that provides comprehensive request and response logging capabilities for LinuxX64 and other targets. It offers configurable detail levels, multiple output formats, header sanitization, and platform-specific logger integrations.
3
4
## Package Information
5
6
- **Package Name**: ktor-client-logging-linuxx64
7
- **Package Type**: maven
8
- **Language**: Kotlin
9
- **Installation**: Implementation provided as part of Ktor Client plugins
10
- **Coordinates**: `io.ktor:ktor-client-logging-linuxx64:3.2.0`
11
12
## Core Imports
13
14
```kotlin
15
import io.ktor.client.plugins.logging.*
16
```
17
18
For HttpClient installation:
19
20
```kotlin
21
import io.ktor.client.*
22
import io.ktor.client.plugins.logging.*
23
```
24
25
## Basic Usage
26
27
```kotlin
28
import io.ktor.client.*
29
import io.ktor.client.plugins.logging.*
30
31
// Install logging plugin with basic configuration
32
val client = HttpClient {
33
install(Logging) {
34
level = LogLevel.HEADERS
35
logger = Logger.DEFAULT
36
}
37
}
38
39
// Or with custom configuration
40
val client = HttpClient {
41
install(Logging) {
42
level = LogLevel.ALL
43
format = LoggingFormat.OkHttp
44
logger = Logger.SIMPLE
45
46
// Filter requests
47
filter { request ->
48
request.url.host.contains("api.example.com")
49
}
50
51
// Sanitize sensitive headers
52
sanitizeHeader { headerName ->
53
headerName == "Authorization"
54
}
55
}
56
}
57
```
58
59
## Architecture
60
61
The Ktor Client Logging plugin is built around several key components:
62
63
- **Plugin Configuration**: `LoggingConfig` class provides DSL-based configuration options
64
- **Logging Levels**: `LogLevel` enum controls what information gets logged (INFO, HEADERS, BODY, ALL, NONE)
65
- **Output Formats**: `LoggingFormat` enum supports Default and OkHttp-style formatting
66
- **Logger Interface**: Abstraction supporting multiple platform-specific implementations
67
- **Request/Response Processing**: Internal pipeline integration for transparent logging
68
- **Content Observation**: Smart binary detection and content type handling
69
70
## Capabilities
71
72
### Plugin Installation and Configuration
73
74
Core plugin installation with comprehensive configuration options including levels, formats, filtering, and header sanitization.
75
76
```kotlin { .api }
77
val Logging: ClientPlugin<LoggingConfig>
78
79
fun HttpClientConfig<*>.Logging(block: LoggingConfig.() -> Unit = {})
80
```
81
82
[Plugin Configuration](./configuration.md)
83
84
### Logging Levels and Control
85
86
Control what information gets logged with granular level settings and request filtering capabilities.
87
88
```kotlin { .api }
89
enum class LogLevel(val info: Boolean, val headers: Boolean, val body: Boolean) {
90
ALL(true, true, true),
91
HEADERS(true, true, false),
92
BODY(true, false, true),
93
INFO(true, false, false),
94
NONE(false, false, false)
95
}
96
```
97
98
[Logging Levels and Control](./levels-and-control.md)
99
100
### Logger Implementations
101
102
Platform-specific logger implementations providing integration with system logging frameworks.
103
104
```kotlin { .api }
105
interface Logger {
106
fun log(message: String)
107
companion object
108
}
109
110
val Logger.Companion.DEFAULT: Logger
111
val Logger.Companion.SIMPLE: Logger
112
val Logger.Companion.EMPTY: Logger
113
```
114
115
[Logger Implementations](./logger-implementations.md)
116
117
### Output Formatting
118
119
Multiple output format options for compatibility with different logging tools and preferences.
120
121
```kotlin { .api }
122
enum class LoggingFormat {
123
Default,
124
OkHttp
125
}
126
```
127
128
[Output Formatting](./output-formatting.md)