logging.md
docs/logging.md
1# Logging23## Logger Setup45- Instantiate the SLF4J logger using `LoggerFactory.getLogger(...)`:6 ```kotlin7 companion object {8 private val log = LoggerFactory.getLogger(FeatureServiceImpl::class.java)9 }10 ```11 or as a private property on the class:12 ```kotlin13 private val log = LoggerFactory.getLogger(javaClass)14 ```1516## Log Levels1718- `ERROR`: Unrecoverable errors and unexpected exceptions.19- `WARN`: Recoverable unexpected states, client-side anomalies, or transient errors.20- `INFO`: Business-relevant milestones and auditable events (e.g., entity created, batch job finished).21- `DEBUG` / `TRACE`: Diagnostic messages for local testing and debugging.2223## Message Format & Placeholders2425Keep log formats uniform across the entire codebase:2627```kotlin28log.info("[<FEATURE>] - ACTION: <method>: <field>: {}", value)29```3031- **Use `{}` placeholders:** Always use parameter placeholders. Never use string concatenation, which incurs performance overhead and risks leaking sensitive data.32- **Traceability:** Include identifiers that facilitate end-to-end tracing across requests (e.g., request ID, user ID).3334## Hygiene & Error Boundary3536- **No sensitive data:** Never log credentials, tokens, passwords, or personal identifiable information (PII).37- **Service layer logging:** Keep logging primarily within the service and application layer.38- **No double logging on exceptions:** Code throwing a domain exception must not log it before throwing. The `GlobalExceptionHandler` logs the exception once at the boundary.3940## Runtime Configuration4142`PAPERLESS_LOG_LEVEL` controls the application package's level and defaults to43`INFO`. Set it to `DEBUG` for HTTP status/duration and search result counts.44Every request receives a server-generated `X-Request-ID`. The same value is45available as `requestId` in SLF4J MDC and appears in the default console pattern.46The filter runs before authentication and clears its MDC value after the request,47including failed requests. Client-provided request IDs are not trusted.4849Services record login, resource creation/update/deletion, and membership changes50with resource IDs. These are operational milestones within a transaction, not a51durable audit trail or proof of transaction commit. Client errors are logged once52at the exception handler or security boundary. Unexpected exceptions are logged53at `ERROR` with their type and stack frames; exception messages are omitted54because they may contain request data.5556Request URLs, query text, request/response bodies, usernames, credentials, bearer57tokens, document titles, filenames, and content are not logged by the application.58