在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):MicroUtils/kotlin-logging开源软件地址(OpenSource Url):https://github.com/MicroUtils/kotlin-logging开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):kotlin-loggingLightweight logging framework for Kotlin, written in . Call log methods, without checking whether the respective log level is enabledlogger.debug { "Some $expensive message!" } Behind the scenes the expensive message do not get evaluated if debug is not enabled: // This is what happens when you write the above ^^^
if (logger.isDebugEnabled) logger.debug("Some $expensive message!") Define the logger, without explicitly specifiying the class name// Place definition above class declaration to make field static
private val logger = KotlinLogging.logger {} Behind the scenes // This is what happens when you write the above ^^^
val logger = LoggerFactory.getLogger("package.ClassName") Log exceptions in a Kotlin-style// exception as first parameter with message as lambda
logger.error(exception) { "a $fancy message about the $exception" } Getting startedimport mu.KotlinLogging
private val logger = KotlinLogging.logger {}
class FooWithLogging {
val message = "world"
fun bar() {
logger.debug { "hello $message" }
}
} An DownloadImportant note: kotlin-logging depends on slf4j-api (in the JVM artifact). In runtime, it is also required to depend on a logging implementation. More details in how-to-configure-slf4j. And an excellent detailed explanation in a-guide-to-logging-in-java. In short, if you just want to log statements to stdout, it's possible to add the following dependency: Maven<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
<version>2.1.20</version>
</dependency> See the full example in kotlin-logging-example-maven. Gradleimplementation 'io.github.microutils:kotlin-logging-jvm:2.1.20' Alternatively, download the JAR from github or bintray or maven-central. MultiplatformAn experimental common & JS & linux-x64 support is available. OverviewAfter seeing many questions like Idiomatic way of logging in Kotlin and Best practices for loggers, it seems like there should be a standard for logging and obtaining a logger in Kotlin. kotlin-logging provides a wrapper for slf4j-api to be used by Kotlin classes with the following advantages:
Who is using it
And many more... (add your name above) FAQ
Usage
It is possible to configure IntelliJ live templates. For file level logger configure the following:
Support
More links
ContributorsAny contribution is appreciated. See the contributors list in: https://github.com/MicroUtils/kotlin-logging/graphs/contributors ContributingPull requests are welcome! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论