Skip to content
Bluetape4k docs1.11

Lazy messages and failure isolation

Latest stable Based on Bluetape4k release 1.11.0

String interpolation, JSON conversion, and collection summaries should not run for a disabled level. Lambda extensions evaluate messages behind the level guard.

log.debug { "Loaded ${records.size} rows: ${records.take(3)}" }
  1. Check isDebugEnabled.
  2. Invoke the supplier only when enabled.
  3. Convert a null result to the string "null".
  4. If the supplier throws, emit fallback text instead of interrupting business flow.

logMessageSafe defaults to Fail to generate log message. and appends the exception text. This isolates service behavior from diagnostic-code failure, but can hide a supplier bug; make fallback occurrences observable in tests and operations.

Every level has message-only, cause-plus-message, and marker-plus-cause-plus-message overloads.

log.warn(validationError) { "Rejected requestId=$requestId" }
log.error(securityMarker, failure) { "Authorization failed" }

WARN and ERROR helpers prefix messages with 🔥. SLF4J level remains the severity contract; do not build alerts by parsing the prefix alone.

// The eager computation already happened.
log.debug(expensiveSnapshot())
// Lazy does not make secrets safe.
log.info { "token=$token" }

Laziness changes evaluation time, not redaction. Capturing a mutable object records its value at evaluation time, so extract the required immutable fields first.

Continue with correlation boundaries in Scoped MDC.