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.
Evaluation order
Section titled “Evaluation order”log.debug { "Loaded ${records.size} rows: ${records.take(3)}" }- Check
isDebugEnabled. - Invoke the supplier only when enabled.
- Convert a
nullresult to the string"null". - 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.
Errors and markers
Section titled “Errors and markers”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.
Avoid these patterns
Section titled “Avoid these patterns”// 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.
Source and tests
Section titled “Source and tests”Continue with correlation boundaries in Scoped MDC.