
Client SDK for a self-hosted logging server; non-blocking, fire-and-forget logging with background batching, retries with exponential backoff, configurable batch/flush settings, bounded queue dropping oldest entries.
Kotlin Multiplatform SDK for MyLogger42 — a small, self-hosted logging server.
One dependency for every platform: Kotlin/JVM, Android, iOS (via KMP), and Java services — the JVM artifact has a Java-friendly API, no coroutines knowledge required.
Available on Maven Central — no extra repository needed.
KMP project — one line in the shared module, covers all targets:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.mylogger42:mylogger42-kotlin:0.1.0")
}
}
}Plain Android / JVM / Java project:
dependencies {
implementation("io.github.mylogger42:mylogger42-kotlin:0.1.0")
}Create one MyLogger per process and reuse it — it owns a background
worker and an HTTP client.
val logger = MyLogger.create(
MyLoggerConfig(
endpoint = "https://logs.example.com",
apiKey = "mlk_…", // ingest key from the MyLogger42 UI
)
)
logger.log("signup", LogLevel.Info, "user registered")
logger.log(
service = "signup",
level = LogLevel.Error,
message = "db unreachable",
metadata = mapOf("err" to "timeout", "userId" to "u_42"),
)
logger.flush() // optional: send what's queued now, don't wait for the batch
logger.close() // on shutdown: drain everything, stop the workerFrom Java, the same API:
MyLogger logger = MyLogger.create(
new MyLoggerConfig("https://logs.example.com", "mlk_…"));
logger.log("signup", LogLevel.Info, "user registered");
logger.log("signup", LogLevel.Error, "db unreachable", Map.of("err", "timeout"));
logger.close();log() is fire-and-forget: it enqueues and returns immediately — it
never blocks the caller, never throws, and never touches the network. A
background worker batches queued entries and POSTs them to
/api/v1/logs/batch:
batchSize or when
flushIntervalMillis elapses — whichever comes first;flush() skips the wait and sends immediately (use before a crash
exit or app background); close() flushes, then stops the worker.
Both return immediately — the final send is best-effort if the
process dies right after.Timestamps are stamped client-side at log() time, so batched entries
keep their real times.
MyLoggerConfig |
Default | Notes |
|---|---|---|
endpoint |
— | Base URL of your MyLogger42 server. |
apiKey |
— | Ingest key (mlk_…), issued per project. |
batchSize |
100 |
Entries per request, max 500 (server cap). |
flushIntervalMillis |
5000 |
Max time an entry waits before being sent. |
Verbose · Debug · Info · Event · Warning · Error · Fatal
— identical to the server's levels.
localhost is the emulator itself — use
http://10.0.2.2:8080 to reach the server on your machine, and allow
cleartext HTTP for local testing (android:usesCleartextTraffic="true")../gradlew jvmTest # unit + Java interop tests
./gradlew iosSimulatorArm64Test # same suite on iOS (needs macOS)
./gradlew publishToMavenLocal # install into ~/.m2End-to-end smoke test against a live server (opt-in):
MYLOGGER42_IT_ENDPOINT=http://localhost:8080 \
MYLOGGER42_IT_KEY=mlk_… \
./gradlew jvmTest --tests "io.github.mylogger42.sdk.IntegrationSmokeTest" --rerunKotlin Multiplatform SDK for MyLogger42 — a small, self-hosted logging server.
One dependency for every platform: Kotlin/JVM, Android, iOS (via KMP), and Java services — the JVM artifact has a Java-friendly API, no coroutines knowledge required.
Available on Maven Central — no extra repository needed.
KMP project — one line in the shared module, covers all targets:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.mylogger42:mylogger42-kotlin:0.1.0")
}
}
}Plain Android / JVM / Java project:
dependencies {
implementation("io.github.mylogger42:mylogger42-kotlin:0.1.0")
}Create one MyLogger per process and reuse it — it owns a background
worker and an HTTP client.
val logger = MyLogger.create(
MyLoggerConfig(
endpoint = "https://logs.example.com",
apiKey = "mlk_…", // ingest key from the MyLogger42 UI
)
)
logger.log("signup", LogLevel.Info, "user registered")
logger.log(
service = "signup",
level = LogLevel.Error,
message = "db unreachable",
metadata = mapOf("err" to "timeout", "userId" to "u_42"),
)
logger.flush() // optional: send what's queued now, don't wait for the batch
logger.close() // on shutdown: drain everything, stop the workerFrom Java, the same API:
MyLogger logger = MyLogger.create(
new MyLoggerConfig("https://logs.example.com", "mlk_…"));
logger.log("signup", LogLevel.Info, "user registered");
logger.log("signup", LogLevel.Error, "db unreachable", Map.of("err", "timeout"));
logger.close();log() is fire-and-forget: it enqueues and returns immediately — it
never blocks the caller, never throws, and never touches the network. A
background worker batches queued entries and POSTs them to
/api/v1/logs/batch:
batchSize or when
flushIntervalMillis elapses — whichever comes first;flush() skips the wait and sends immediately (use before a crash
exit or app background); close() flushes, then stops the worker.
Both return immediately — the final send is best-effort if the
process dies right after.Timestamps are stamped client-side at log() time, so batched entries
keep their real times.
MyLoggerConfig |
Default | Notes |
|---|---|---|
endpoint |
— | Base URL of your MyLogger42 server. |
apiKey |
— | Ingest key (mlk_…), issued per project. |
batchSize |
100 |
Entries per request, max 500 (server cap). |
flushIntervalMillis |
5000 |
Max time an entry waits before being sent. |
Verbose · Debug · Info · Event · Warning · Error · Fatal
— identical to the server's levels.
localhost is the emulator itself — use
http://10.0.2.2:8080 to reach the server on your machine, and allow
cleartext HTTP for local testing (android:usesCleartextTraffic="true")../gradlew jvmTest # unit + Java interop tests
./gradlew iosSimulatorArm64Test # same suite on iOS (needs macOS)
./gradlew publishToMavenLocal # install into ~/.m2End-to-end smoke test against a live server (opt-in):
MYLOGGER42_IT_ENDPOINT=http://localhost:8080 \
MYLOGGER42_IT_KEY=mlk_… \
./gradlew jvmTest --tests "io.github.mylogger42.sdk.IntegrationSmokeTest" --rerun