Introduction
Colotok is a Kotlin Multiplatform logging library.
Features
Console, file, and stream output
Text and JSON formatting
Size-based and duration-based file rotation
Structured logging with Kotlin serialization
Mapped Diagnostic Context (MDC)
Runtime metrics
Custom providers and formatters
Loki, CloudWatch, and SLF4J integrations
Installation
For a JVM or Android project, add the core dependency:
For a Kotlin Multiplatform project, add the root artifact to commonMain:
The core module, colotok-coroutines, and colotok-loki support JVM, Android, JS/Node, iosArm64, iosSimulatorArm64, and macosArm64. Apple x86 targets (iosX64 and macosX64) are not supported in 1.0.0. Gradle module metadata selects the target-specific variant from the common dependency; do not add target-suffixed coordinates manually.
Integration modules
Colotok provides several plugins to extend its functionality:
plugin | artifact | feature | Platform |
|---|---|---|---|
colotok-coroutines |
| coroutine support | Multi Platform |
colotok-slf4j |
| SLF4J 1.7.x bindings (JVM only) | JVM |
colotok-slf4j2 |
| SLF4J 2.x bindings (JVM only) | JVM |
colotok-cloudwatch |
| send logs to AWS CloudWatch | JVM |
colotok-loki |
| send logs to Grafana Loki | Multi Platform |
Kotlin serialization
Structured logging requires the Kotlin serialization compiler plugin because message classes use @Serializable. The colotok artifact already exposes the serialization runtime required by its public API, so a separate runtime dependency is normally unnecessary.
Colotok 1.0.0 is built with Kotlin/KGP 2.4.21. Use Kotlin 2.4.21 for JS/Node: Kotlin 2.3.21 cannot read the JS KLIB ABI produced by 2.4.21. See compiler compatibility for the tested compiler and platform combinations.
Usage
Create a logger
Create a Context, add a Provider, and obtain a logger:
Configure each Provider before adding it to the Context:
Write logs
Use a method matching the log level: