LogField

A log field is a key-value pair for adding structured data to logs.

When outputting logs as JSON (using e.g. logstash-logback-encoder), this becomes a field in the logged JSON object. That allows you to filter and query on the field in the log analysis tool of your choice, in a more structured manner than if you were to just use string concatenation.

There are 3 ways to add log fields in this library:

If you have a value that is already serialized, you can use LogBuilder.rawJsonField or the rawJsonField top-level function.

If there are duplicate keys in the fields that would apply to a log, we only add 1 of the fields (to avoid duplicate keys in the JSON log output). Fields are prioritized as follows:

  1. Single-log fields (from LogBuilder.field)

  2. Exception log fields (from ExceptionWithLoggingContext)

  3. Logging context fields (from withLoggingContext)

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Two log fields are equal if their keys and values are equal.

Link copied to clipboard
open override fun hashCode(): Int

Returns the combined hash code of the key and value for this log field.

Link copied to clipboard
open override fun toString(): String

Returns a string representation of the log field, formatted as ${key}=${value}.