run.qontract.LogUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qontract-core Show documentation
Show all versions of qontract-core Show documentation
A Contract Testing Tool that leverages Gherkin to describe APIs in a human readable and machine enforceable manner
package run.qontract
import java.util.*
object LogTail {
var n: Int = 5000
private var logs = Collections.synchronizedList(LinkedList())
private var snapshot = emptyList()
@OptIn(ExperimentalStdlibApi::class)
fun append(line: String) {
logs.size
logs.add(line)
if(logs.size > n && logs.isNotEmpty()) {
logs.removeFirst()
}
}
fun append(logs: List) {
val joined = logs.joinToString(System.lineSeparator())
append(joined)
}
fun storeSnapshot() {
snapshot = logs.toList()
}
fun getString(): String = logs.joinToString("\n")
fun getSnapshot(): String = snapshot.joinToString("\n")
internal fun clear() {
logs.clear()
}
}
fun consoleLog(event: String) {
LogTail.append(event)
println(event)
}
val nullLog = { event: String ->
LogTail.append(event)
}