StructuredLog

MDC-style thread-local context manager for structured logging.

Values set via putLogContext are automatically included in all subsequent structured log entries on the same thread. Each thread maintains its own independent context, so this object is safe to use from multiple threads concurrently without synchronization.

StructuredLog.putLogContext("user_id", userId)
StructuredLog.putLogContext("session_id", sessionId)

// All logs below will include user_id and session_id.
StructuredTimber.d("Purchase completed", "item_id" to "SKU-123")

Since

1.0.0

Functions

Link copied to clipboard

Clear all entries from the current thread's context.

Link copied to clipboard
fun putLogContext(key: String, value: Any?)

Add a key-value pair to the current thread's context.

Link copied to clipboard

Remove a key from the current thread's context.

Link copied to clipboard
fun <R> withLogContext(vararg entries: Pair<String, Any?>, block: () -> R): R

Execute block with the given entries added to the current thread's context.