KSLog
1.6.1indexedSimple, customizable logging tool supporting multiple platforms. Offers built-in logging for various environments, lazy message evaluation, and custom logger creation options.
Simple, customizable logging tool supporting multiple platforms. Offers built-in logging for various environments, lazy message evaluation, and custom logger creation options.
It is simple and easy-to-use tool for logging on the most popular platforms in Kotlin Multiplatform:
By default, KSLog is using built-in tools for logging on each supported platform:
java.util.logging.Logger for JVMandroid.util.Log for AndroidConsole for JSBut you always may create your logger and customize as you wish:
KSLog.default = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
// do your logging
}
This library also supports native targets in experimental mode. By default all native targets will use simple printing in the console
Just use some boring extensions like:
KSLog.i()
KSLog.i(, )
KSLog.i(, , IllegalArgumentException())
KSLog.i(, Exception()) { }
KSLog.iS(, Exception()) { }
KSLog.l(LogLevel.INFO, , , IllegalArgumentException())
KSLog.l(LogLevel.INFO, , IllegalArgumentException()) { }
There are several important "terms" in context of this library:
Every logging extension (like KSLog.i) have its analog with lazy inited message text and the same one with suffix S (like KSLog.iS) for the suspendable message calculation.
Default logger can be created by passing defaultTag and one of variants log level filters: set or minimal loggable level. In JVM you also may setup any logger as base logger for default realizations of KSLog. Besides, you may use your own callback (on any target platform) as output of logging:
val logger = KSLog { logLevel, optionalTag, message, optionalThrowable ->
println("[$logLevel] $optionalTag - $message: $optionalThrowable.stackTraceToString()")
}
In the example above we will take the logger which will just print incoming data as common output.
implementation "dev.inmo:kslog:$kslog_version"
<dependency>
<groupId>dev.inmo</groupId>
<artifactId>kslog</artifactId>
<version>${kslog_version}</version>
</dependency>
KSLog.default or simply KSLog)KSLog functions and passed anywhere as KSLog)KSLog.i/KSLog.infoAny.logger which allow you to create logger binded to the default with the tag based on the class of receiver
apply, the receiver will be different with your class inside of that applySurfaced from shared tags and platforms — no rankings paid for.