diff --git a/src/main/kotlin/ch/leadrian/slf4k/Slf4k.kt b/src/main/kotlin/ch/leadrian/slf4k/Slf4k.kt index c266857..51db6ef 100644 --- a/src/main/kotlin/ch/leadrian/slf4k/Slf4k.kt +++ b/src/main/kotlin/ch/leadrian/slf4k/Slf4k.kt @@ -20,6 +20,7 @@ package ch.leadrian.slf4k import org.slf4j.Logger import org.slf4j.LoggerFactory import org.slf4j.Marker +import kotlin.reflect.KClass /** * @return a logger for the given parameterized type [T] @@ -30,12 +31,14 @@ inline fun loggerFor(): Logger = LoggerFactory.getLogger(T::cl * @return a logger for the given receiver type [T] or it's declaring class in case of a companion class */ @Suppress("unused") -inline fun T.logger(): Logger { - val classToLog = when { - T::class.isCompanion -> T::class.java.declaringClass ?: T::class.java - else -> T::class.java +inline fun T.logger(): Logger = LoggerFactory.getLogger(resolveClassToLog(T::class)) + +@PublishedApi +internal fun resolveClassToLog(inputClass: KClass<*>): Class { + return when { + inputClass.isCompanion -> inputClass.java.declaringClass ?: inputClass.java + else -> inputClass.java } - return LoggerFactory.getLogger(classToLog) } /**