From c667a82fdabd117fbedab0a235683bf2c40a05ea Mon Sep 17 00:00:00 2001 From: leadrian Date: Sun, 25 Jul 2021 00:45:49 +0200 Subject: [PATCH] Extract some functionality into non-inline functions --- src/main/kotlin/ch/leadrian/slf4k/Slf4k.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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) } /**