Skip to content

What it is

Kermit is a Kotlin Multiplatform logging library from Touchlab that routes to Logcat on Android, os_log on Apple platforms and stdout elsewhere.

Log with severity levels, attach tags and throwables, and configure per-platform log writers at startup.

Installation

implementation("co.touchlab:kermit:2.0.4")

Getting started

The smallest useful thing you can do with it, and what each part means.

Logging from shared code
// Lambdas mean the message is not built when the level is disabled.
Logger.i { "Loading books for user $userId" }
Logger.d { "cache hit ratio ${hits.toDouble() / total}" }
Logger.e(exception) { "failed to sync" }

// A tagged logger per component.
private val log = Logger.withTag("BookRepository")
log.w { "falling back to cache" }

// Configure once at startup.
Logger.setLogWriters(platformLogWriter())
Logger.setMinSeverity(if (isDebug) Severity.Verbose else Severity.Info)
The lambda form is why this beats a plain string API: at Info level the debug string is never constructed, so verbose logging costs nothing in release builds.

Advanced usage

Where the library earns its place over a simpler alternative.

Crash reporting and test capture
// Route warnings and above into crash reporting breadcrumbs.
class CrashlyticsWriter : LogWriter() {
    override fun isLoggable(tag: String, severity: Severity) =
        severity >= Severity.Warn

    override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
        Crashlytics.log("$tag: $message")
        throwable?.let { Crashlytics.recordException(it) }
    }
}

Logger.setLogWriters(platformLogWriter(), CrashlyticsWriter())

// Assert on log output in tests.
val writer = TestLogWriter(loggable = Severity.Verbose)
Logger.setLogWriters(writer)
repository.sync()
assertTrue(writer.logs.any { it.severity == Severity.Error })
A custom LogWriter is how log lines become crash-report breadcrumbs. When a crash arrives, the preceding log context is usually what identifies the cause.

Errors and fixes

The failures you are most likely to hit, and what actually resolves them.

Nothing appears on iOS
os_log filters by level. Check minSeverity, and use Console.app or Xcode rather than expecting stdout.
Logs are missing in release
Intended if minSeverity was raised. Route warnings and errors to crash reporting so they are still visible.

Best practices

  • Use the lambda form so disabled log messages cost nothing to construct.
  • Create a tagged logger per class rather than passing tags at every call.
  • Raise the minimum severity in release builds.
  • Never log tokens, personal data or full payloads — mobile logs are readable on device.

Background

Why it exists, and what it was reacting to.

println works everywhere but is unusable in production. Kermit gives shared Multiplatform code one logging API that lands in each platform's native logging system where the tooling can see it.