<commit_before>package io.github.vyo.twig.logger

import io.github.vyo.twig.appender.Appender
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.shouldBeTrue
import org.jetbrains.spek.api.shouldEqual
import java.util.*
import kotlin.test.fail

/**
 * Created by <NAME> on 28.11.2015.
 */
class LoggerSpec : Spek() {
    init {
        given("nothing") {
            on("initialisation") {
                it("should setup root logger log threshold") {
                    shouldEqual(Level.INFO, Logger.threshold)
                }
            }
            on("invocation") {
                it("should be able to log messages as 'root'") {
                    Logger.info("logging test $this")
                }
            }
        }
        given("a custom field name \'custom\'") {
            var log: ArrayList<String> = arrayListOf()

            class StringAppender : Appender {
                override fun write(logEntry: String) {
                    println(logEntry)
                    log.add(logEntry)
                }

            }

            val customLogger: Logger = Logger("customTestLogger", StringAppender(), arrayOf("custom", "audit",
                    "retention"))
            on("invocation") {
                it("should add the custom field to the JSON log entry") {
                    customLogger.info("some test message", "", "classified", "none")

                    var retriesLeft: Int = 5
                    while (log.size == 0 && retriesLeft != 0) {
                        Thread.sleep(1)
                        retriesLeft--
                    }
                    if (retriesLeft == 0) fail("failed to write to log")

                    shouldBeTrue(log.get(0).contains("classified"))
                }
            }
        }

    }
}<commit_msg>Adjust specification<commit_after>package io.github.vyo.twig.logger

import io.github.vyo.twig.appender.Appender
import nl.komponents.kovenant.async
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.shouldBeTrue
import org.jetbrains.spek.api.shouldEqual
import java.util.*
import kotlin.test.fail

/**
 * Created by <NAME> on 28.11.2015.
 */
class LoggerSpec : Spek() {
    companion object DummyLog {
        private class StringAppender : Appender {
            var log: ArrayList<String> = arrayListOf()

            override fun write(logEntry: String) {
                log.add(logEntry)
            }
        }

        val appender: StringAppender = StringAppender()

        var entries: ArrayList<String> = appender.log
            get() {
                return appender.log
            }

        fun size(): Int {
            return entries.size
        }

        fun clear() {
            entries.clear()
        }

        override fun toString(): String {
            return entries.toString()
        }

    }

    init {
        Logger.root.appender = DummyLog.appender

        given("nothing") {

            on("initialisation") {
                it("should setup root logger log threshold") {
                    shouldEqual(Level.INFO, Logger.threshold)
                }
            }

            on("invocation") {
                it("should be able to log messages as 'TwigRootLogger'") {
                    async {
                        Logger.info("root test message")

                        var retriesLeft: Int = 5
                        while (retriesLeft != 0) {
                            var entryFound: Boolean = false
                            for (entry in DummyLog.entries) {
                                if (entry.contains("TwigRootLogger") && entry.contains("root test message"))
                                    entryFound = true
                            }
                            println(DummyLog)
                            shouldBeTrue(entryFound)
                            Thread.sleep(5)
                            retriesLeft--
                        }
                        if (retriesLeft == 0) fail("failed to write to log")
                    } fail {
                        fail(it.message)
                    }
                }
            }

            on("changing the root log level") {
                it("should log the change") {

                }
            }

            on("changing the root appender") {
                it ("should log the change") {

                }
            }
        }

        given("a logger with a custom field name \'custom\'") {

            //            beforeOn {
            //                DummyLog.clear()
            //            }

            val customLogger: Logger = Logger("customTestLogger", customFields = arrayOf("custom", "audit",
                    "retention"))
            on("invocation") {
                it("should add the custom field to the JSON log entry") {
                    async {
                        customLogger.info("some test message", "", "classified", "none")

                        var retriesLeft: Int = 5
                        while (retriesLeft != 0) {
                            var entryFound: Boolean = false
                            for (entry in DummyLog.entries) {
                                if (entry.contains("classified") && entry.contains("customTestLogger")) entryFound =
                                        true
                            }
                            println(DummyLog)
                            shouldBeTrue(entryFound)
                            Thread.sleep(5)
                            retriesLeft--
                        }
                        if (retriesLeft == 0) fail("failed to write to log")
                    } fail {
                        fail(it.message)
                    }
                }
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.09422283356258597, 'fraction_numerical': 0.00515818431911967, 'mean_word_length': 1.1083725987676694, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4936320', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1347, 'n_words': 322}