If content-type is json
or hal+json
, it will automatically output the beautified json.
Before | After |
---|---|
This plugin is implemented in the same way as the official ktor-client-logging
.
However, there are three differences:
- all interfaces/properties are prefixed with
JsonAware
. - the
Logger
interface has afun prettifyJson(json: String): String = json
function is added. - 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()
.
ktor-client-logging-json
:ktor-client-logger-moshi
:ktor-client-logger-jackson
:ktor-client-logger-gson
:
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}")
}