Log Builder
Class used in the logging methods on Logger, allowing you to add structured key-value data to the log by calling the field and rawJsonField methods.
This class is provided as a receiver for the buildLog
lambda parameter on Logger
's methods, which lets you call its methods directly in the scope of the lambda. This is a common pattern for creating type-safe builders in Kotlin (see the Kotlin docs for more on this).
Example
private val log = getLogger()
fun example(event: Event) {
log.info {
// This lambda gets a LogBuilder receiver, which means that we can call `LogBuilder.field`
// directly in this scope
field("event", event)
"Processing event"
}
}
Content copied to clipboard
Functions
Link copied to clipboard
Adds the given log fields to the log. This is useful when you have a list of previously constructed fields from the field/rawJsonField top-level functions, that you want to add to a single log.
Link copied to clipboard
Adds a log field (structured key-value data) to the log, with the given pre-serialized JSON value.