▲ 32 r/KotlinMultiplatform+4 crossposts

log4k 2.3.0 — a Kotlin IR compiler plugin that instruments your functions with tracing, logging and metrics

log4k 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.

Details that mattered while building it:

  • suspend and regular functions are both supported; the generated wrapper delegates to inline helpers ( Logger.logged, Meter.Timed.measure, TracingContext.traced), so there's no per-call lambda allocation.
  • The plugin reuses your existing log / meter / trace members if they're thesynthesizes private val _log_ = Logger.of( this::class) under a distinct name,so it never clashes with e.g. an existing SLF4J log.
  • All three annotations work class-level too — annotate the class to instrummember. Per-function annotations override the class defaults, and @NoLog / @NoTime / @NoTrace opt out a single function or the whole class.
  • The metric instrument bundle is created once and cached per name.

The plugin is marked experimental — behavior and API may still change.

Repo: https://github.com/smyrgeorge/log4k

Compiler Plugin: https://github.com/smyrgeorge/log4k#compiler-plugin

Docs: https://smyrgeorge.github.io/log4k/

Feedback welcome, especially on the annotation surface and on cases where thon't pick what you'd expect.

u/smyrgeorge — 12 days ago
▲ 11 r/KotlinMultiplatform+1 crossposts

[sqlx4k] Now with SQLCipher Support: Encrypted SQLite for Kotlin Multiplatform (Android, JVM, Native)

Hey everyone!

I'm excited to share the latest update for sqlx4k (v1.9.0), a Kotlin Multiplatform library for SQL databases.

The big news in this release is the official support for SQLCipher! You can now easily implement encrypted SQLite databases across Android, JVM, and Native targets with a unified API.

What’s new?

  • sqlx4k-sqlite-cipher: A new module specifically for encrypted SQLite.
  • True Multiplatform: Works seamlessly on Android (via JNI), JVM, and Native (via FFI).

Quick Example:

val db = sqliteCipher(
    context = androidContext, // for Android
    url = "sqlite:/path/to/secure.db",
    password = "your-secret-passphrase",
    options = ConnectionPool.Options.builder().maxConnections(5).build()
)

// Use it just like standard SQLx4K
val rows = db.select("SELECT * FROM users WHERE id = ?").bind(1).fetch()

Check it out on GitHub: io.github.smyrgeorge/sqlx4k

Would love to hear your feedback or if you have any questions about the implementation!

u/smyrgeorge — 3 months ago
▲ 14 r/creativecoding+1 crossposts

QRT: A screen-to-camera data transfer protocol, using QR codes (proof of concept)

This project explores data transfer using a screen-to-camera approach. The idea is simple: encode information into a sequence of QR codes, display them as a video on a screen, and then use a camera to capture and decode the video frames to retrieve the original data.

github.com
u/smyrgeorge — 12 days ago