Skip to main content

Klogging and Ktor

Klogging can be used in Ktor applications easily.

Many Ktor JVM modules specify SLF4J as a dependency. The Ktor Project Generator specifies Logback as a dependency and generates a src/main/resources/logback.xml configuration file.

Configuration

The simplest way to configure Klogging is to replace the Logback dependency with that for Klogging:

dependencies {
// Ktor engine and plugin dependencies
// implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.klogging:slf4j-klogging:0.8.0")

// Other dependencies
}

Add src/main/resources/klogging.json configured as described in Configuration with JSON, for example:

{
"sinks": {
"stdout": {
"renderWith": "RENDER_ANSI",
"sendTo": "STDOUT"
}
},
"logging": [
{
"levelRanges": [
{
"fromMinLevel": "INFO",
"stopOnMatch": true,
"toSinks": [
"stdout"
]
}
]
}
]
}