Skip to content

jisungbin/ktor-client-logging-json

Repository files navigation

ktor-client-logging-json

If content-type is json or hal+json, it will automatically output the beautified json.

Before After
image image

Usage

This plugin is implemented in the same way as the official ktor-client-logging. 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-logging-json
  • ktor-client-logger-moshi: ktor-client-logger-moshi
  • ktor-client-logger-jackson: ktor-client-logger-jackson
  • ktor-client-logger-gson: 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}")
}

About

If content-type is json or hal+json, it will automatically output the beautified json.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages