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

run.qontract.LogUtils.kt Maven / Gradle / Ivy

Go to download

A Contract Testing Tool that leverages Gherkin to describe APIs in a human readable and machine enforceable manner

There is a newer version: 0.23.1
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy