shafirov/klogging


Kotlin logging, both js and jvm

License: Apache-2.0

Language: Kotlin


KLogging

KLogging provides unified logging API, which you can use from Kotlin code targeted for both JVM and Javascript. The library is inspired by

KLogger class features 5 levels of logging (to mirror that of SLF4J): trace, debug, info, warn, error with 2 flavors each:

logger.trace("This string will be evaluated regardless if trace enabled = ${logger.isTraceEnabled}")
logger.trace {"This string will not be evaluated unless trace enabled = ${logger.isTraceEnabled}"}

To obtain an instance of a logger you need to call one of the logger() methods of KLoggers (please note that JVM version of this class provides more overloads) or use mix it in:

class Foo {
    val logger = KLoggers.logger(this)

    fun test() {
        logger.info("Have some logging!")    
    }
}

class Bar : WithLogging by KLoggerHolder() {
    fun test() {
        logger.info("Have some logging!")    
    }
}

class Baz {
    companion object: WithLogging by KLoggerHolder() 

    fun test() {
        logger.info("Have some logging!")    
    }
} 

For file-level loggers I recommend following IntelliJ IDEA live template:

<template name="log" value="private val log = klogging.KLoggers.logger(&quot;$LOGGER_NAME$&quot;)" description="Logger" toReformat="false" toShortenFQNames="true">
  <variable name="LOGGER_NAME" expression="groovyScript(&quot;com.intellij.openapi.module.ModuleUtil.findModuleForFile(_editor.virtualFile, _editor.project).name   \&quot;/\&quot;   _editor.virtualFile.name&quot;) " defaultValue="" alwaysStopAt="false" />
  <context>
    <option name="KOTLIN_TOPLEVEL" value="true" />
  </context>
</template>

Project Statistics

Sourcerank 4
Repository Size 120 KB
Stars 16
Forks 3
Watchers 4
Open issues 0
Dependencies 0
Contributors 1
Tags 2
Created
Last updated
Last pushed

Top Contributors See all

Maxim Shafirov

Recent Tags See all

1.0.4-1 October 04, 2016
1.1.0-1 October 03, 2016

Interesting Forks See all

Lewik/klogging
Kotlin logging for js, jvm and common
Kotlin - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2016-10-04 10:00:14 UTC

Login to resync this repository