Reputation: 51
I'm migrating my Kotlin project to use oshai's kotlin-logging.
I am using a legacy library which has dependency on SLF4J Logger, but KLogger in oshai's kotlin-logging doesn't inherit it any more.
Slf4j dependency is not provided anymore (users have to provide it). It means that >= 5.x can work with both slf4j 1 or 2.
Here's the existing legacy class:
class MyLegacyClass(
private val log: org.slf4j.Logger
)
My previous implementation looked like this:
import mu.KotlinLogging
class MyClass() : MyLegacyClass(log) {
companion object {
private val log = KotlinLogging.logger {}
}
}
I need to migrate to oshai's kotlin-logging, which doesn't inherit org.slf4j.Logger any more.
Here is the new library:
import io.github.oshai.kotlinlogging.KotlinLogging
My Problem:
I need to access the SLF4J Logger from the KLogger
instance to pass it to the MyLegacyClass
. The previous method using mu.KotlinLogging
allowed accessing the underlying SLF4J logger. How can I achieve this with oshai's kotlin-logging?
Alternatively, could I exclusively use SLF4J in my Kotlin class? What are the implications?
Attempted Solutions:
Tried accessing underlyingLogger
property, but it doesn't exist in the new KLogger
.
Explored the library documentation but couldn't find a direct method to unwrap the KLogger
.
Useful links:
Upvotes: 5
Views: 243