agentleFS
oshaioshai/kotlin-logging/llms.txt

kotlin-logging

llms.txt3.1k starsChanged 10 days agoApache-2.0View on GitHub

Lightweight, idiomatic, lazy-evaluated logging facade for Kotlin Multiplatform (io.github.oshai:kotlin-logging). Wraps SLF4J (with optional direct Logback / JUL backends) on JVM, SLF4J or native android.util.Log on Android, Apple Unified Logging (os_log) on macOS/iOS/watchOS/tvOS, and configurable console/direct logging across JS, WebAssembly (wasmJs, wasmWasi), Linux, Windows, and Android Native. Set System.setProperty("kotlin-logging-to-android-native", "true") once before first logger initialization to route logs directly to android.util.Log without SLF4J. On SLF4J 2.0 and direct Logback backends, payload entries are forwarded as structured key-value pairs.

Trending

More talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 2 mentionsFeb 2026: 4 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 2 mentionsJun 2026: 3 mentionsJul 2026: 1 mentionAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 9 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the oshai/kotlin-logging repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about oshai/kotlin-logging

The biggest 5 of 50 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 50

Talked about on GitHub (50 times).

On GitHub · 50

45 more on GitHub

The file

We split this llms.txt into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Canonical coordinates & package (5.0.0+ / 8.x): Always use Maven group ID io.github.oshai and package io.github.oshai.kotlinlogging.

    line 7
  2. Very specific:

    Lazy {} lambdas or fluent builders only (8.0.0+): All non-lambda String? overloads on KLogger (including logger.info("msg"), …

    line 8

≈ “Common” is an estimate: at least 1 in 5 of the 3,727 llms.txt files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
llms.txt
# kotlin-logging

> Lightweight, idiomatic, lazy-evaluated logging facade for Kotlin Multiplatform (`io.github.oshai:kotlin-logging`). Wraps SLF4J (with optional direct Logback / JUL backends) on JVM, SLF4J or native `android.util.Log` on Android, Apple Unified Logging (`os_log`) on macOS/iOS/watchOS/tvOS, and configurable console/direct logging across JS, WebAssembly (`wasmJs`, `wasmWasi`), Linux, Windows, and Android Native.

## Critical Rules for Code Generation

- **Canonical coordinates & package (`5.0.0+` / `8.x`)**: Always use Maven group ID `io.github.oshai` and package `io.github.oshai.kotlinlogging`. **Never** use the legacy `3.x` group ID `io.github.microutils` or `import mu.*` (`mu.KotlinLogging`, `mu.KLogger`, `mu.withLoggingContext`).
- **Lazy `{}` lambdas or fluent builders only (`8.0.0+`)**: All non-lambda `String?` overloads on `KLogger` (including `logger.info("msg")`, `logger.error("msg", ex)`, and `logger.info("msg {}", arg)`) were removed in `8.0.0`. Every log call in `8.x` must use a trailing `{}` lambda (`logger.info { "msg" }`, `logger.error(ex) { "msg" }`) or a fluent builder (`logger.atInfo { ... }`).
- **Explicit SLF4J runtime on JVM**: `kotlin-logging-jvm` declares `org.slf4j:slf4j-api` as `compileOnly` so applications can choose SLF4J `2.x` or `1.7.x`. Always add an SLF4J backend (such as `ch.qos.logback:logback-classic` or `org.slf4j:slf4j-simple:2.0.20`) in JVM applications.
- **Avoid deprecated APIs**: Declare a file-level `private val logger = KotlinLogging.logger {}` instead of inheriting from deprecated `KLogging()` / `KLoggable`, and do not pass the deprecated `restorePrevious` parameter to `withLoggingContextAsync`.

## Dependencies (`8.0.7`)

### Gradle (Kotlin DSL — JVM)

```kotlin
dependencies {
    implementation("io.github.oshai:kotlin-logging-jvm:8.0.7")
    runtimeOnly("org.slf4j:slf4j-simple:2.0.20") // or ch.qos.logback:logback-classic
}
```

### Kotlin Multiplatform (`commonMain`)

```kotlin
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.oshai:kotlin-logging:8.0.7")
        }
    }
}
```

### Android

```kotlin
dependencies {
    implementation("io.github.oshai:kotlin-logging-android:8.0.7")
}
```

Set `System.setProperty("kotlin-logging-to-android-native", "true")` once before first logger initialization to route logs directly to `android.util.Log` without SLF4J.

### Coroutines MDC (`jvmMain`)

```kotlin
dependencies {
    implementation("io.github.oshai:kotlin-logging-jvm:8.0.7")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:1.10.2")
}
```

## Idiomatic `8.x` Usage

### Obtaining a Logger & Lazy Logging

```kotlin
import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger {}

class OrderService {
    fun process(orderId: String) {
        logger.debug { "Starting order $orderId" }
        try {
            logger.info { "Completed order $orderId" }
        } catch (e: Exception) {
            // Throwable is always the FIRST argument; message lambda is LAST
            logger.error(e) { "Failed processing order $orderId" }
            throw e
        }
    }
}
```

- On JVM/Android, `KotlinLogging.logger {}` inside nested or inner classes resolves to the enclosing top-level class name; pass `KotlinLogging.logger(Outer.Inner::class.java.name)` when a distinct nested logger name is needed.
- On Kotlin/JS, `private val logger by KotlinLogging.logger()` is also available inside classes.

### Fluent Structured Logging (`atTrace` / `atDebug` / `atInfo` / `atWarn` / `atError`)

```kotlin
logger.atInfo {
    message = "Order processed"
    cause = optionalException
    payload = mapOf(
        "orderId" to orderId,
        "items" to itemCount,
    )
}
```

On SLF4J 2.0 and direct Logback backends, `payload` entries are forwarded as structured key-value pairs.

### Synchronous MDC (`withLoggingContext` — JVM)

```kotlin
import io.github.oshai.kotlinlogging.withLoggingContext

withLoggingContext("requestId" to requestId, "userId" to userId) {
    logger.info { "Handling request" }
}
```

### Coroutines MDC (`withLoggingContextAsync` — JVM + `kotlinx-coroutines-slf4j`)

```kotlin
import io.github.oshai.kotlinlogging.coroutines.withLoggingContextAsync

suspend fun handleRequest(requestId: String) {
    withLoggingContextAsync("requestId" to requestId) {
        logger.info { "MDC preserved across suspension points" }
    }
}
```

### Multiplatform Direct Logger Configuration (JS, Wasm, Native)

```kotlin
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
import io.github.oshai.kotlinlogging.Level

KotlinLoggingConfiguration.direct.logLevel = Level.DEBUG
```

## Documentation

- [API Reference (Dokka)](https://oshai.github.io/kotlin-logging/): Multiplatform KDoc API documentation for `commonMain`, `jvmMain`, `androidMain`, `darwinMain`, `jsMain`, `wasmJsMain`, `wasmWasiMain`, and `nativeMain`.
- [README](https://github.com/oshai/kotlin-logging/blob/master/README.md): Project overview, installation snippets, multiplatform target list, and FAQ.
- [OpenRewrite Migration Guide](https://github.com/oshai/kotlin-logging/blob/master/docs/openrewrite/README.md): Automated migration recipe (`io.github.oshai.kotlinlogging.UpgradeToKotlinLogging8`) for upgrading from `io.github.microutils` (`mu.*`) to `io.github.oshai` `8.x`.
- [OpenRewrite Recipe YAML](https://github.com/oshai/kotlin-logging/blob/master/docs/openrewrite/rewrite.yml): Declarative OpenRewrite recipe definition.
- [Multiplatform Support Wiki](https://github.com/oshai/kotlin-logging/wiki/Multiplatform-support): Platform-specific configuration for JVM, Android, JS, WebAssembly, Apple (`os_log`), Linux, and Windows.
- [Changelog & Major Versions](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog.md): Summary of breaking changes across versions `1.x` through `8.x`.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.