All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.typed.TypedKSLogBuilder.kt Maven / Gradle / Ivy

package dev.inmo.kslog.common.typed

import dev.inmo.kslog.common.*
import kotlin.reflect.KClass

class TypedKSLogBuilder(
    private val preset: Map?, KSLog> = emptyMap()
) {
    private val loggers = mutableMapOf?, KSLog>().apply {
        putAll(preset)
    }

    fun on(kClass: KClass<*>?, with: KSLog) = loggers.put(kClass, with)
    fun on(kClass: KClass<*>?, with: SimpleKSLogCallback) = loggers.put(kClass, CallbackKSLog(with))

    fun default(with: KSLog) = on(null, with)
    fun default(with: SimpleKSLogCallback) = on(null, with)

    inline fun  on(with: KSLog) = on(T::class, with)
    inline fun  on(noinline with: SimpleKSLogCallback) = on(T::class, with)

    fun build() = TypedKSLog(loggers.toMap())
}

inline fun buildTypedLogger(
    preset: Map?, KSLog> = emptyMap(),
    block: TypedKSLogBuilder.() -> Unit
) = TypedKSLogBuilder(preset).apply(block).build()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy