Yorgos S.
07/26/2026, 7:48 AMlog4k is a coroutine/channel-based logging + tracing + metering library for Kotlin Multiplatform (JVM, Android, iOS,
macOS, Linux, Windows, JS, wasmJs, wasmWasi), aligned with the OpenTelemetry model.
The recent addition is log4k-compiler-plugin — a Kotlin IR compiler plugin that rewrites annotated functions at compile
time, so the instrumentation boilerplate disappears from your source. It runs on common IR before backend lowering, so
the same annotations work on every KMP target — not just the JVM (no AspectJ, no bytecode agent, no reflection).
Setup — one Gradle plugin, no extra config:
plugins {
id("io.github.smyrgeorge.log4k") version "2.3.0"
}
dependencies {
implementation("io.github.smyrgeorge:log4k-classic:2.3.0")
}
@Traced — wraps the body in a span (started, ended, marked failed on throw):
@Traced
context(_: TracingContext)
suspend fun loadUser(id: Long): User {
// ...
} // span "UserService.loadUser"
The parent span is resolved from what's in scope: a TracingContext param/receiver → nests under its current span; else a
TracingEvent.Span in scope → used as parent; else a trace: Tracer member (reused, or synthesized) → new root span.
@Logged — entry/exit/failure logging:
@Logged
fun compute(x: Int): Int = x * x
// → UserService.compute(x = 5)
// ← UserService.compute = 25(12.5 us)
Throwing logs ✗ UserService.compute failed (…) at ERROR with the throwable, then rethrows. If a span is in scope
it's attached to every emitted line.
@Timed — call/error counters + a duration histogram:
@Timed(tags = [Tag("tier", "gold")])
suspend fun placeOrder(id: Long): Order {
// ...
}
Records OrderService.placeOrder.calls, .errors and .duration (ms histogram) — exportable in OpenMetrics line
format via SimpleMeteringCollectorAppender.
The plugin is marked experimental — behavior and API may still change.
Feedback welcome, especially on the annotation surface and on cases where thon't pick what you'd expect.
Repo: github.com/smyrgeorge/log4k
Compiler Plugin: github.com/smyrgeorge/log4k#…
Docs: smyrgeorge.github.io/log4kaltavir
07/26/2026, 1:01 PMYorgos S.
07/26/2026, 2:10 PMaltavir
07/26/2026, 2:11 PMYorgos S.
07/26/2026, 2:15 PMaltavir
07/26/2026, 2:17 PMaltavir
07/26/2026, 2:18 PMYorgos S.
07/26/2026, 2:20 PMYorgos S.
07/26/2026, 2:22 PMDidier Villevalois
07/27/2026, 9:51 AMYorgos S.
07/27/2026, 9:57 AMSlf4jLoggingAppender for a logging appender that forwards to slf4j . I also plan to publish the appender that I’m using in some personal projects that sends the traces to a local open telemetry agent.
For metering, you can also check the SimpleMeteringCollectorAppender that creates an OpenMetrics formatted string