commonMain.kr.jadekim.logger.option.JLoggerOptionProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of j-logger-jvm Show documentation
Show all versions of j-logger-jvm Show documentation
Logging Library for Kotlin
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