Skip to content

Multiplatform support

Ohad Shai edited this page Nov 20, 2024 · 15 revisions

Modules

As of version 2.0 kotlin-logging has multiplatfom support. It composed of various modules for the specific platform:

  • Common - artifact id: kotlin-logging
  • JVM - artifact id: kotlin-logging-jvm
  • JS - artifact id: kotlin-logging-js
  • Linux - artifact id: kotlin-logging-linuxx64

Full list of modules can be found in: https://repo1.maven.org/maven2/io/github/oshai/

In order to include in gradle build file add the following dependency:

compile 'io.github.oshai:<artifact id>:<version>'
  • First supported version is 5.0.0 (for the new artifacts).
  • It is sufficient to add the dependency on the common module.

Common usage

Obtaining a logger is supported only by a field (no inheritance at the moment):

private val logger = KotlinLogging.logger {}

KLogger log messages support only lazy methods messages such as:

logger.info { "Hello World!" }

JS usage

All common interfaces and methods are supported.
In addition, in order to define log level set field KotlinLoggingConfiguration.logLevel during startup.
For example:

KotlinLoggingConfiguration.logLevel = Level.DEBUG
  • Default level is INFO

In JS there are many settings (browsers, node) that works a bit differently for name resolution. It is also possible to configure logger name like this (since version 5):

class MyClass {
  private val logger by KotlinLogging.logger()
}

Linux usage

All common interfaces and methods are supported.
In addition, in order to define log level set field KotlinLoggingConfiguration.logLevel during startup.
For example:

KotlinLoggingConfiguration.logLevel = Level.DEBUG
  • Default level is INFO