https://github.com/jisungbin/ktor-client-logging-json
If content-type is json or hal+json, it will automatically output the beautified json.
https://github.com/jisungbin/ktor-client-logging-json
ktor-client logging
Last synced: 5 months ago
JSON representation
If content-type is json or hal+json, it will automatically output the beautified json.
- Host: GitHub
- URL: https://github.com/jisungbin/ktor-client-logging-json
- Owner: jisungbin
- Created: 2023-10-16T08:08:48.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T07:54:39.000Z (about 2 years ago)
- Last Synced: 2024-06-22T14:41:44.194Z (about 2 years ago)
- Topics: ktor-client, logging
- Language: Kotlin
- Homepage:
- Size: 190 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ktor-client-logging-json
If content-type is `json` or `hal+json`, it will automatically output the beautified json.
| Before | After |
| :---: | :---: |
|  |  |
### Usage
This plugin is implemented in the same way as the official [`ktor-client-logging`](https://ktor.io/docs/client-logging.html).
However, there are three differences:
1. all interfaces/properties are prefixed with `JsonAware`.
2. the `Logger` interface has a `fun prettifyJson(json: String): String = json` function is added.
3. the default log level is raised to `LogLevel.Body`.
Added to the `Logger` interface, the `prettifyJson(json: String): String` function is called when
the content to be logged is of type `json` or `hal+json`, and the result is logged.
The Json deserialization library to use for the `prettifyJson()` implementation comes with
the Moshi, Jackson, and Gson implementations by default.
By default, the Json deserialization rules are as follows:
- Indent 2 spaces
- Allow `null`
- Allow lenient json
The specific implementations are available as `JsonAwareLogger.useMoshi()`, `JsonAwareLogger.useJackson()`, and `JsonAwareLogger.useGson()`.
### Download
- `ktor-client-logging-json`: 
- `ktor-client-logger-moshi`: 
- `ktor-client-logger-jackson`: 
- `ktor-client-logger-gson`: 
```kotlin
dependencies {
implementation("land.sungbin.ktor.client.logging:ktor-client-logging-json:${version}")
implementation("land.sungbin.ktor.client.logger:ktor-client-logger-moshi:${version}")
implementation("land.sungbin.ktor.client.logger:ktor-client-logger-jackson:${version}")
implementation("land.sungbin.ktor.client.logger:ktor-client-logger-gson:${version}")
}
```