LogBuilder

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"
}
}

Functions

Link copied to clipboard
fun addField(field: LogField)

Adds the given log field to the log. This is useful when you have a previously constructed field from the field/rawJsonField top-level functions, that you want to add to a single log.

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
inline fun <ValueT> field(key: String, value: ValueT)
fun <ValueT : Any> field(key: String, value: ValueT?, serializer: SerializationStrategy<ValueT>)

Adds a log field (structured key-value data) to the log.

Link copied to clipboard
fun rawJsonField(key: String, json: String, validJson: Boolean = false)

Adds a log field (structured key-value data) to the log, with the given pre-serialized JSON value.