Skip to content
Bluetape4k docs1.11

Operations, configuration, and recipes

Latest stable Based on Bluetape4k release 1.11.0

Correct API calls are insufficient when backend configuration or lifecycle is wrong. Operations must verify that required fields are emitted safely and delivered before shutdown.

<pattern>%date %-5level [%thread] traceId=%X{traceId} requestId=%X{requestId} %logger - %msg%n</pattern>

Map the same keys as structured fields when using a JSON encoder. The application repository owns this configuration; a library must not modify the root logger.

suspend fun handle(call: ApplicationCall) {
val requestId = sanitize(call.request.headers["X-Request-Id"])
?: UUID.randomUUID().toString()
withCoroutineLoggingContext("requestId" to requestId) {
log.info { "Request accepted" }
service.execute()
}
}

Bound external values by length and character set before adding them to MDC. Exclude tokens, cookies, authorization headers, and raw bodies from both MDC and messages.

MDC tests should assert:

  • the value inside the block;
  • restoration after a nested scope;
  • restoration after an exception;
  • removal after restorePrevious=false;
  • no installation for null entries;
  • propagation across dispatcher switches.

Channel tests use a capturing appender for levels, ordering, prefixes, and causes. They also verify an inactive collector after closeAndJoin(), idempotent close, and post-close drop.

Terminal window
./gradlew :bluetape4k-logging:test --no-configuration-cache
SymptomBoundary to inspectAction
request ID intermittently missingplain MDC crossed a coroutine boundarywrap the suspend operation with the coroutine helper
CPU grows while DEBUG is disabledeager message or serializationmove work into the lambda extension
logs disappear near shutdownasync close was mistaken for drainmove important events to a durable path
duplicate linesmultiple providers/appenders or additivityinspect runtime classpath and Logback hierarchy
repeated fallback messagessupplier exceptiontest and simplify message construction

No dedicated logging workshop is registered. The smallest runnable exercise is to apply the recipe at a Ktor or Spring request boundary and add nested-MDC and shutdown tests.