Logger foundation
Latest stable Based on Bluetape4k release 1.11.0
The declaration style determines call-site ergonomics, name stability, and how operators identify a logger.
Two entry points
Section titled “Two entry points”Use KLogging when a class or companion object should share a log property. Kotlin lazy creates the logger once on first access.
class InvoiceService { companion object : KLogging()
fun issue() { log.info { "Issuing invoice" } }}Use KotlinLogging for top-level code, an explicit category, or a KClass name.
private val auditLog = KotlinLogging.logger("billing.audit")private val fileLog = KotlinLogging.logger { }val serviceLog = KotlinLogging.logger(InvoiceService::class)Naming contract
Section titled “Naming contract”logger(name) rejects a blank name with IllegalArgumentException. The lambda entry point and KLogging delegate synthetic and companion-name normalization to KLoggerNameResolver. Prefer an explicit category when the name is a stable dashboard or routing key.
Provider boundary
Section titled “Provider boundary”The module returns SLF4J Logger; it does not install a backend. The application owns one provider such as Logback and its configuration. A library must not silently replace appenders or root levels.
Decision table
Section titled “Decision table”| Situation | Choice |
|---|---|
| Every instance uses one category | companion KLogging() |
| File or top-level function | KotlinLogging.logger {} |
| Stable operational category | logger("stable.name") |
| Explicit type-based category | logger(Type::class) |
Source and tests
Section titled “Source and tests”Next: control evaluation cost and supplier failure in Lazy messages.