commonMain.kr.jadekim.logger.JLog.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
import co.touchlab.stately.collections.SharedHashMap
import kr.jadekim.logger.option.JLoggerOptionProvider
import kr.jadekim.logger.pipeline.*
internal expect fun init()
@Suppress("VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL")
object JLog {
var loggerLevel = LogLevel.INFO
var pipeline: MutableList = mutableListOf(
LoggerNameShorter(),
TextFormatter(),
StdOutPrinter(),
)
var optionProvider = JLoggerOptionProvider.builder().build()
private val loggers = SharedHashMap()
init {
init()
}
fun get(name: String): JLogger = loggers.getOrPut(name) {
val option = optionProvider[name]
JLogger(name, option.level, option.pipeline)
}
fun installPipe(vararg pipe: JLogPipe) {
pipe.forEach { it.install(pipeline, pipeline.size) }
}
fun installPipeBefore(reference: JLogPipe.Key, pipe: Pipe) {
var index = pipeline.indexOfFirst { it == reference }
if (index == -1) {
index = 0
}
pipe.install(pipeline, index)
}
fun installPipeAfter(reference: JLogPipe.Key, pipe: Pipe) {
var index = pipeline.indexOfFirst { it.key == reference }
if (index == -1) {
index = pipeline.size
}
pipe.install(pipeline, index)
}
fun uninstallPipe(pipeKey: JLogPipe.Key) {
pipeline.removeAll { it.key == pipeKey }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy