Log Field
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:
Adding fields to a single log: Use LogBuilder.field in the scope of one of the methods on Logger (see example on LogBuilder.field).
Adding fields to all logs in a scope: Use withLoggingContext, with the field top-level function to construct log fields (see example on withLoggingContext).
Adding fields to an exception: Use ExceptionWithLoggingContext (see example on its docstring).
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:
Single-log fields (from LogBuilder.field)
Exception log fields (from ExceptionWithLoggingContext)
Logging context fields (from withLoggingContext)