From 92378ee81547c5bd301eb9d5fd9ef271fb5a1edf Mon Sep 17 00:00:00 2001 From: oshai Date: Mon, 3 Jul 2023 09:32:26 +0300 Subject: [PATCH] add payload to LocationAwareKLogger --- .../slf4j/internal/LocationAwareKLogger.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt index 9e833078..8ce57cf5 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt @@ -10,6 +10,7 @@ import io.github.oshai.kotlinlogging.slf4j.isLoggingEnabledFor import io.github.oshai.kotlinlogging.slf4j.toSlf4j import org.slf4j.event.EventConstants import org.slf4j.helpers.MessageFormatter +import org.slf4j.spi.CallerBoundaryAware import org.slf4j.spi.LocationAwareLogger /** @@ -35,7 +36,14 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { if (isLoggingEnabledFor(level, marker)) { KLoggingEventBuilder().apply(block).run { - underlyingLogger.log(marker?.toSlf4j(), fqcn, level.toSlf4j().toInt(), message, null, cause) + val builder = underlyingLogger.atLevel(level.toSlf4j()) + marker?.toSlf4j()?.let { builder.addMarker(it) } + payload?.forEach { (key, value) -> builder.addKeyValue(key, value) } + builder.setCause(cause) + if (builder is CallerBoundaryAware) { + builder.setCallerBoundary(fqcn) + } + builder.log(message) } } }