Logger
Deprecated
The OpenSavvy Logger library is deprecated and won't be maintained anymore. We do not plan on deleting the library, but we do not plan on improving it either. We encourage you to switch to another logging library.
Multiplatform interface for logger implementations.
Logging for a class can be implemented as follows:
class Foo {
init {
log.trace { "Foo's constructor was called!" }
}
companion object {
private val log = loggerFor(this)
}
}
The messages included or excluded can be selected using level. For example, to only display error messages for a specific class, use:
class Foo {
companion object {
private val log = loggerFor(this)
init {
log.level = LogLevel.ERROR
}
}
}
To set the log level for the entire program, see LogLevel.default.
The available logging methods are:
They all accept the same arguments:
zero or more objects, which will be appended to the message
a lambda producing a message, which will only be evaluated if the given level is enabled.
Examples:
log.level { "Simple form" }
log.level(obj1, obj2) { "With two objects" }
Because the various logging methods are inline and check that their level is enabled early, logging using this interface is performant no matter the implementation.
The loggerFor method is used to instantiate a platform-specific implementation. On Kotlin/JS, it uses the console
object. On Kotlin/JVM, it uses the Slf4j library, you will need to include a Slf4j binding in your project.