kotlin-logging is a free, open source monitoring & observability project written in Kotlin and released under Apache-2.0. It has 3,116 GitHub stars, 131 forks and 21 open issues, and was last pushed 9 hours ago. On this registry it ranks #134 of 270 tracked projects in Monitoring & Observability, with 5 head-to-head comparisons available. It gained 3 stars over the last 30 tracked days.

What is kotlin-logging?

kotlin-logging is a lightweight, pure-Kotlin logging facade that gives JVM, Android, and multiplatform Kotlin applications lazy, idiomatic log calls while delegating the actual logging work to SLF4J and whichever backend implementation the project already uses.

What it is

kotlin-logging is a thin facade written entirely in Kotlin that sits in front of the SLF4J API on the JVM. It does not implement logging itself; it wraps an existing logging backend so that Kotlin code can call loggers in idiomatic Kotlin instead of Java-style APIs. Logger creation, level checks, exception logging, and structured payloads are all expressed with Kotlin language constructs such as lambdas, default arguments, and builder blocks.

The concrete problem it solves is boilerplate and cost in Kotlin logging. Traditionally, a developer must obtain a logger by passing an explicit class name string, and must guard every expensive message with an isDebugEnabled check to avoid building strings that are then discarded. kotlin-logging replaces both patterns: KotlinLogging.logger {} derives the logger name from the enclosing class or file automatically, and logger.debug { "Some $expensive message!" } defers message construction until the level is confirmed enabled. It lives in the Kotlin/JVM and Kotlin multiplatform ecosystem, and it replaces hand-written SLF4J wrapper code that teams otherwise duplicate across every module.

Key capabilities

  • Lazy message evaluation: logger.debug { "Some $expensive message!" } skips lambda evaluation when debug is disabled, avoiding the explicit if (logger.isDebugEnabled) guard.
  • Automatic logger naming: private val logger = KotlinLogging.logger {} resolves to LoggerFactory.getLogger("package.ClassName") without a class-name literal.
  • Kotlin-style exception logging: logger.error(exception) { "a $fancy message about the $exception" } takes the throwable first and the message as a lambda.
  • Fluent logging DSL: logger.atWarn { message = "foo $bar"; cause = exception; payload = buildMap(capacity = 3) { ... } } supports message, cause, and structured payload in one block.
  • SLF4J-backed on the JVM: the JVM artifact depends on slf4j-api and routes to any SLF4J implementation present at runtime.
  • Multiplatform support for Android, JVM, and other targets, with experimental multiplatform documentation on the project wiki.
  • Standard distribution artifacts: io.github.oshai:kotlin-logging-jvm:7.0.3 on Maven Central, with released JARs also available from GitHub releases.

Who uses it and how

  • Android application teams that want lazy log statements without shipping a full logging framework, keeping the Android runtime dependency footprint small.
  • JVM backend services already standardized on SLF4J and Logback or another backend, where kotlin-logging only changes the calling syntax and not the pipeline.
  • Kotlin multiplatform projects that need one logging call site for shared code across JVM, Android, and additional targets, accepting that multiplatform support is still experimental.
  • Library and SDK authors who ship Kotlin code and want callers to see familiar SLF4J behavior without forcing a specific implementation.
  • Teams migrating from handwritten SLF4J wrappers, who adopt the facade module by module while the underlying logging configuration stays untouched.

Getting started

Add implementation 'io.github.oshai:kotlin-logging-jvm:7.0.3' to Gradle, or the equivalent Maven dependency on io.github.oshai:kotlin-logging-jvm:7.0.3; then supply a runtime SLF4J implementation, for example org.slf4j:slf4j-simple:2.0.3 to print to stdout.

How it compares

The closest named tool in these facts is SLF4J itself: kotlin-logging is a Kotlin-facing layer over slf4j-api, not a competing backend, so choosing it does not change which implementation writes the logs. It sits alongside implementations such as slf4j-simple rather than replacing them, and it is distributed under Apache-2.0 from Maven Central as io.github.oshai:kotlin-logging-jvm.

When to use it — and when not to

Adoption requires supplying an SLF4J implementation at runtime; the facade alone produces no output, and from version 5 onward the slf4j-api dependency must also be declared by the user. Multiplatform support is documented as experimental, so projects targeting non-JVM platforms should expect to track open issues rather than rely on a stable contract. Teams that want out-of-the-box formatting, appenders, or configuration should pick a backend first and treat this as a calling-convention improvement only.

project readme (upstream, from github) — read inline

kotlin-logging CI Slack channel Maven Central Apache License V.2 Kotlin GitHub stars image

Lightweight Multiplatform logging framework for Kotlin, written in Pure Kotlin.
A convenient and performant logging facade.

Call log methods, without checking whether the respective log level is enabled
logger.debug { "Some $expensive message!" }

Behind the scenes the expensive message do not get evaluated if debug is not enabled:

// This is what happens when you write the above ^^^
if (logger.isDebugEnabled) logger.debug("Some $expensive message!")
Define the logger, without explicitly specifying the class name
// Place definition above class declaration to make field static
private val logger = KotlinLogging.logger {}

Behind the scenes val logger will be created in the class, with the class/file name:

// This is what happens when you write the above ^^^
val logger = LoggerFactory.getLogger("package.ClassName")
Log exceptions in a Kotlin-style
// exception as first parameter with message as lambda
logger.error(exception) { "a $fancy message about the $exception" }
Fluent logging in a Kotlin-style
logger.atWarn {
    message    = "foo $bar"
    cause      = exception
    payload    = buildMap(capacity = 3) {
        put("foo", 1)
        put("bar", "x")
        put("obj", Pair(2, 3))
    }
}

Getting started

import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger {} 

class FooWithLogging {
    val message = "world"
    fun bar() {
        logger.debug { "hello $message" }
    }
}

Download

Important note: kotlin-logging depends on slf4j-api (in the JVM artifact). In runtime, it is also required to depend on a logging implementation. More details in how-to-configure-slf4j. And an excellent detailed explanation in a-guide-to-logging-in-java.
In version 5 users should also provide slf4j-api dependency.

In short, if you just want to log statements to stdout, it's possible to add the following dependency: org.slf4j:slf4j-simple:2.0.3.

<dependency>
  <groupId>io.github.oshai</groupId>
  <artifactId>kotlin-logging-jvm</artifactId>
  <version>7.0.3</version>
</dependency>

See the full example in kotlin-logging-example-maven.

Gradle

implementation 'io.github.oshai:kotlin-logging-jvm:7.0.3'

Alternatively, download the JAR from github or maven-central.

Multiplatform

An experimental multiplatform support is available.
More information is available on the wiki and issues #21 #45.

Overview

After seeing many questions like Idiomatic way of logging in Kotlin and Best practices for loggers, it seems like there should be a standard for logging and obtaining a logger in Kotlin. kotlin-logging provides a wrapper for slf4j-api to be used by Kotlin classes with the following advantages:

  • No need to write the logger and class name or logger name boilerplate code.
  • A straight forward way to log messages with lazy-evaluated string using lambda expression {}.
  • All previous slf4j implementation can still be used.

Version 5 vs. previous versions

Version 5 is not backward compatible with previous versions (v.3, v.2, v.1). Group id (in maven) and packages names changed. It is possible to use both version 5 and previous versions side-by-side so some of the code from the old version and some new. It is also possible to have libs using old version and use the new version (and vice-versa).
In that sense it's a completely new dependency.

Main changes are:

  • Maven group id changed from io.github.microutils -> io.github.oshai.
  • Root package change from mu -> io.github.oshai.kotlinlogging.
  • Slf4j dependency is not provided anymore (users have to provide it). It means that >= 5.x can work with both slf4j 1 or 2.
  • There are changes to multiplatform class hierarchy that might break compatibility.

More details in issue #264, and in the change log

Who is using it

And many more... (add your name above)

FAQ

  • Why not use plain slf4j? kotlin-logging has better native Kotlin support. It adds more functionality and enables less boilerplate code.
  • Is all slf4j implementation supported (Markers, params, etc')? Yes.
  • Is location logging possible? Yes, location awareness was added in kotlin-logging 1.4.
  • When I do logger.debug, my IntelliJ IDEA run console doesn't show any output. Do you know how I could set the console logger to debug or trace levels? Is this an IDE setting, or can it be set in the call to KLogging()? Setting log level is done per implementation. kotlin-logging and slf4j are just facades for the underlying logging lib (log4j, logback etc') more details here.
  • Can I access the actual logger? In platforms available yes, via DelegatingKLogger.underlyingLogger property.

Usage

  • See wiki for more examples.

It is possible to configure IntelliJ live templates. For file level logger configure the following:

  • Text template: private val logger = io.github.oshai.kotlinlogging.KotlinLogging.logger {}.
  • Applicable in Kotlin: top-level.

Support

More links

Contributing

Any contribution is appreciated.

Pull requests are welcome! See instructions in https://github.com/oshai/kotlin-logging/blob/master/CONTRIBUTING.md.

Show your ❤ with a ★

Thank you to all the developers who have contributed to kotlin-logging!

See the full contributors list in: https://github.com/oshai/kotlin-logging/graphs/contributors

Frequently asked questions

Is kotlin-logging free to use?

kotlin-logging is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does kotlin-logging do?

Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade.

What is kotlin-logging written in?

kotlin-logging is primarily written in Kotlin. Its source is publicly available at https://github.com/oshai/kotlin-logging, and it has 3,116 GitHub stars.