Skip to content

Latest commit

 

History

History
77 lines (58 loc) · 1.87 KB

README.md

File metadata and controls

77 lines (58 loc) · 1.87 KB

klog

This project is not abandonned. It's just nothing to add.

KLogging provides unified logging API, which you can use from Kotlin code targeted for JVM, Javascript common kotlin (and native soon).

Download

Use https://jitpack.io repository

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
compile 'com.github.lewik.klog:klog-metadata:2.0.5'

Usage

class Foo {
    val log = KLoggers.logger(this)
    
    fun test() {
        log("This string will be evaluated regardless if trace enabled = ${log.isTraceEnabled}")
        log {"This string will not be evaluated unless trace enabled = ${log.isTraceEnabled}"}
    
        log("debug level")
        log { "debug level" }
        
        log.trace("trace")
        log.debug("debug")
        log.info("info")
        log.warn("warn")
        log.debug("error")
        
        log.trace { "trace" }
        log.debug { "debug" }
        log.info { "info" }
        log.warn { "warn" }
        log.debug { "error" }
    }
}

Another ways to obtain logger:

class Bar {
    private val log = KLoggers.logger(this)
    
    fun test() { log("Have some logging!") }
}

class Baz : WithLogging by KLoggerHolder() {
    fun test() { log("Have some logging!") }
}
 
class Qux {//*
    companion object: WithLogging by KLoggerHolder() 
    
    fun test() { log("Have some logging!") }
} 

* Qux: https://en.wikipedia.org/wiki/Metasyntactic_variable

Inspired by