oshai/kotlin-logging

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

sleeyax opened this issue · 2 comments

I just installed the library and used it like in the README:

build.gradle.kts:

 implementation("io.github.oshai:kotlin-logging-jvm:5.1.0")

manager.kt:

private val logger = KotlinLogging.logger {}

class Manager {
    fun xxx() {}
}

But I can't get it working at all. As soon as I try to run my program I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
	at io.github.oshai.kotlinlogging.slf4j.internal.Slf4jLoggerFactory.jLogger$kotlin_logging(Slf4jLoggerFactory.kt:11)
	at io.github.oshai.kotlinlogging.internal.KLoggerFactory.logger$kotlin_logging(KLoggerFactory.kt:16)
	at io.github.oshai.kotlinlogging.KotlinLogging.logger(KotlinLogging.kt:23)
	at io.github.oshai.kotlinlogging.KotlinLogging.logger(KotlinLogging.kt:13)
	at com.sleeyax.ManagerKt.<clinit>(Manager.kt:12)
	at com.sleeyax.Manager.xxx(Manager.kt:17)
	at com.sleeyax.MainKt.main(Main.kt:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 7 more

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

It looks like I need to add a dependency to SLF4J and another logging library. I assumed kotlin-logging would be a simple standalone implementation but I guessed wrong. It's actually in the README but I skipped that section too fast.