commonMain.kr.jadekim.logger.pipeline.StdOutPrinter.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.pipeline
import kr.jadekim.logger.Log
import kr.jadekim.logger.LogLevel
import kr.jadekim.logger.SerializedLog
internal expect fun eprintln(text: String)
class StdOutPrinter(
val printStackTrace: Boolean = true,
val useStdErr: Boolean = true,
) : JLogPipe {
companion object Key : JLogPipe.Key
override val key = Key
override fun install(pipeline: MutableList, index: Int) {
if (pipeline.any { StdOutPrinter::class.isInstance(it) }) {
return
}
pipeline.add(index, this)
}
override fun handle(log: Log): Log {
when (log) {
is SerializedLog.String -> {
if (log.level.isPrintableAt(LogLevel.ERROR)) {
eprintln(log.data)
} else {
println(log.data)
}
}
else -> println("ERROR: StdOutPrinter is only acceptable SerializedLog.String. Require to install TextFormatter")
}
if (printStackTrace) {
log.throwable?.printStackTrace()
}
return log
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy