Skip to content

Commit 92378ee

Browse files
committed
add payload to LocationAwareKLogger
1 parent cc90ea7 commit 92378ee

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.github.oshai.kotlinlogging.slf4j.isLoggingEnabledFor
1010
import io.github.oshai.kotlinlogging.slf4j.toSlf4j
1111
import org.slf4j.event.EventConstants
1212
import org.slf4j.helpers.MessageFormatter
13+
import org.slf4j.spi.CallerBoundaryAware
1314
import org.slf4j.spi.LocationAwareLogger
1415

1516
/**
@@ -35,7 +36,14 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
3536
override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) {
3637
if (isLoggingEnabledFor(level, marker)) {
3738
KLoggingEventBuilder().apply(block).run {
38-
underlyingLogger.log(marker?.toSlf4j(), fqcn, level.toSlf4j().toInt(), message, null, cause)
39+
val builder = underlyingLogger.atLevel(level.toSlf4j())
40+
marker?.toSlf4j()?.let { builder.addMarker(it) }
41+
payload?.forEach { (key, value) -> builder.addKeyValue(key, value) }
42+
builder.setCause(cause)
43+
if (builder is CallerBoundaryAware) {
44+
builder.setCallerBoundary(fqcn)
45+
}
46+
builder.log(message)
3947
}
4048
}
4149
}

0 commit comments

Comments
 (0)