aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/DokkaLogging.kt
blob: 4b671f7be983b049e6931d6e28859fae195635f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.jetbrains.dokka.utilities

interface DokkaLogger {
    var warningsCount: Int
    var errorsCount: Int
    fun debug(message: String)
    fun info(message: String)
    fun progress(message: String)
    fun warn(message: String)
    fun error(message: String)
    fun report()
}

object DokkaConsoleLogger : DokkaLogger {
    override var warningsCount: Int = 0
    override var errorsCount: Int = 0

    override fun debug(message: String)= println(message)

    override fun progress(message: String) = println("PROGRESS: $message")

    override fun info(message: String) = println(message)

    override fun warn(message: String) = println("WARN: $message").also { warningsCount++ }

    override fun error(message: String) = println("ERROR: $message").also { errorsCount++ }

    override fun report() {
        if (warningsCount > 0 || errorsCount > 0) {
            println("Generation completed with $warningsCount warning" +
                    (if(warningsCount == 1) "" else "s") +
                    " and $errorsCount error" +
                    if(errorsCount == 1) "" else "s"
            )
        } else {
            println("generation completed successfully")
        }
    }
}