Skip to content

Commit

Permalink
add payload to LocationAwareKLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed Jul 3, 2023
1 parent cc90ea7 commit 92378ee
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 92378ee

Please sign in to comment.