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

commonMain.kr.jadekim.logger.option.JLoggerOptionProvider.kt Maven / Gradle / Ivy

There is a newer version: 2.0.10
Show newest version
package kr.jadekim.logger.option

import kr.jadekim.logger.JLog

interface JLoggerOptionProvider {

    companion object {
        fun builder() = JLoggerOptionProviderBuilder()
    }

    operator fun get(loggerName: String): JLoggerOption
}

class JLoggerOptionProviderImpl(
    private val exactly: Map,
    private val prefix: List>,
) : JLoggerOptionProvider {

    override operator fun get(loggerName: String): JLoggerOption = exactly[loggerName]
        ?: prefix.firstOrNull { loggerName.startsWith(it.first) }?.second
        ?: JLoggerOption(JLog.loggerLevel, JLog.pipeline)
}

class JLoggerOptionProviderBuilder {

    private val exactly: MutableMap = mutableMapOf()
    private val prefix: MutableList> = mutableListOf()

    fun exactly(loggerName: String, option: JLoggerOption): JLoggerOptionProviderBuilder {
        exactly[loggerName] = option

        return this
    }

    fun prefix(loggerName: String, option: JLoggerOption): JLoggerOptionProviderBuilder {
        prefix.add(loggerName to option)
        prefix.sortByDescending { it.first }

        return this
    }

    fun build(): JLoggerOptionProvider = JLoggerOptionProviderImpl(exactly, prefix)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy