Skip to content

Multiplatform support

oshai edited this page Aug 7, 2023 · 13 revisions

Modules

As of version 2.0 kotlin-logging composed of the following modules:

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

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

compile 'io.github.oshai:<artifact id>:<version>'
  • First supported version is 2.0.2.
  • 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.LOG_LEVEL during startup.
For example:

KotlinLoggingConfiguration.LOG_LEVEL = KotlinLoggingLevel.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 = KotlinLoggingLevel.DEBUG
  • Default level is INFO