io.aviso.logging.mdc

added in 0.2.0

Allows arbitrary keys and values to be added to the event MDC.

*extra-mdc*

dynamic

May contain a map of extra values to add to the logging MDC (message diagnostic context).

The keys of the map are converted to string (via clojure.core/name). The values of the map are converted to string via .toString(); null values are not added to the MDC.

Note: the appender adds values to the MDC, which is stored as a mutable value by Logback. Values stored into the MDC may “stick” in the per-thread MDC data and be visible in later logging, even after exiting the with-mdc block.

For best results, invoke set-mdc-default at application startup, setting a default for each key that may later be added to the MDC by a call to with-mdc.

set-mdc-default

(set-mdc-default defaults)

Alters the root value for the *extra-mdc* var, merging keys and values.

Each key is converted to a string using name.

The value is usually an empty string.

This ensures that MDC set by with-mdc doesn’t leak out into subsequent logging on the same thread.

to-string-keys

(to-string-keys m)

with-mdc

macro

(with-mdc mdc-values & body)

Binds a map key/value pair into *extra-mdc* before evaluating the body.