Simple multiplatform logging in Kotlin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
InsanusMokrassar b1d5ce2135
Merge pull request #22 from InsanusMokrassar/1.0.0
3 weeks ago
.github/workflows update publishing workflows 2 months ago
gradle Update libs.versions.toml 4 weeks ago
src add native platforms support 5 months ago
.gitignore Initial commit 8 months ago Update 4 weeks ago
LICENSE Initial commit 8 months ago add platforms support badges 2 months ago
build.gradle add native platforms support 5 months ago add publication workaround 8 months ago
defaultAndroidSettings.gradle Initial commit 8 months ago
dokka.gradle dokka.gradle 8 months ago
github_release.gradle Update github_release.gradle 6 months ago start 1.0.0 4 weeks ago
gradlew Initial commit 8 months ago
gradlew.bat Initial commit 8 months ago
publish.gradle update publishing scripts 2 months ago
publish.kpsb update publishing scripts 2 months ago
settings.gradle perestroika 8 months ago


It is simple and easy-to-use tool for logging on the most popular platforms in Kotlin Multiplatform:

JVM Android Js ARM x64 ARM x32 Linux x64

KDocs Tutorials

By default, KSLog is using built-in tools for logging on each supported platform:

  • java.util.logging.Logger for JVM
  • android.util.Log for Android
  • Console for JS

But you always may create your logger and customize as you wish:

KSLog.default = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
    // do your logging

This library also supports native targets in experimental mode. By default all native targets will use simple printing in the console

How to use


Just use some boring extensions like:

KSLog.i("Some message")
// OR
KSLog.i("Some tag", "Some message")
// OR
KSLog.i("Some tag", "Some message", IllegalArgumentException("So, that is exception :)"))
// OR
KSLog.i("Some optional tag", Exception("Optional")) { "Lazy inited message" }
// OR
KSLog.iS("Some optional tag", Exception("Optional")) { "Lazy inited message for suspendable calculation of text" }
KSLog.l(LogLevel.INFO, "Some tag", "Some message", IllegalArgumentException("So, that is exception :)"))
// OR
KSLog.l(LogLevel.INFO, "Some optional tag", IllegalArgumentException("So, that is exception :)")) { "And lazily inited message" }

A little bit deeper

There are several important "terms" in context of this library:

  • Default logger (available via KSLog.default or simply KSLog)
  • Local logger (can be created via KSLog functions and passed anywhere as KSLog)
  • Logging shortcuts like KSLog.i/
  • Built-in extension Any.logger which allow you to create logger binded to the default with the tag based on the class of receiver
    • Be careful with the receivers: if you will use some extension like apply, the receiver will be different with your class inside of that apply

Every logging extension (like KSLog.i) have its analog with lazy inited message text and the same one with suffix S (like KSLog.iS) for the suspendable message calculation.

Default logger can be created by passing defaultTag and one of variants log level filters: set or minimal loggable level. In JVM you also may setup any logger as base logger for default realizations of KSLog. Besides, you may use your own callback (on any target platform) as output of logging:

val logger = KSLog { logLevel, optionalTag, message, optionalThrowable ->
    println("[$logLevel] $optionalTag - $message: $optionalThrowable.stackTraceToString()")

In the example above we will take the logger which will just print incoming data as common output.


Maven Central


implementation "dev.inmo:kslog:$kslog_version"