groovy
dependencies {
implementation 'io.github.microutils:kotlin-logging:2.0.7'
}
kotlin
import mu.KotlinLogging
class MyClass {
private val logger = KotlinLogging.logger {}
// Rest of the code...
}
kotlin
class MyClass {
private val logger = KotlinLogging.logger {}
fun doSomething() {
logger.info("Doing something...")
// Rest of the code...
}
}
kotlin
class MyClass {
private val logger = KotlinLogging.logger {}
fun doSomething() {
try {
// Code that potentially throws an exception...
} catch (e: Exception) {
logger.error(e) { "An error occurred: ${e.message}" }
}
}
}