Slf4jCacheListener
A CacheListener that writes one structured SLF4J line per cache event.
val cache = SemanticCache(embedder, listeners = listOf(Slf4jCacheListener()))Each event becomes a log record with key/value fields — scope, similarity, reason, guard, the stage latencies — so a structured backend (Logback with a JSON encoder, ELK, Loki) can index them and a plain console still prints them readably. Everything logs at a single configurable level (default DEBUG, since hits and misses are per-request and noisy), and the whole method short-circuits when that level is disabled, so a listener left on in production costs almost nothing.
Prompt redaction is on by default
Prompts are user input and routinely carry PII, so by default the prompt text is never logged — only its length, as promptChars. That keeps the line useful for spotting a hot-scope or a latency spike without turning your log store into a copy of every question your users asked. Set redactPrompts to false in a development or trusted environment to log the (length-capped) text under the prompt field.
Correlation
Pass correlationId to stamp each line with a request/trace id — for example { MDC.get("traceId") } to pull whatever your web framework already put in the SLF4J MDC. It is read once per event and, when non-null, added as a correlationId field. (MDC values your logging config already renders are not duplicated here.)
Thread-safe as long as the logger is, which every SLF4J logger is.
Parameters
the SLF4J logger to write to; defaults to one named dev.kmemo.cache.
the level every event is logged at.
whether to withhold prompt text (on by default); false logs it, length-capped.
when prompts are not redacted, the longest prefix logged before truncation.
supplies a per-event correlation id, or null for none.