-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward Dokka Generator messages to Gradle logger (#3833)
* Forward Dokka Generator messages to Gradle logger
- Loading branch information
Showing
5 changed files
with
342 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
dokka-runners/dokka-gradle-plugin/src/test/kotlin/internal/LoggerAdapterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package internal | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.shouldBe | ||
import org.jetbrains.dokka.gradle.internal.LoggerAdapter | ||
import org.slf4j.event.SubstituteLoggingEvent | ||
import org.slf4j.helpers.NOPLogger | ||
import org.slf4j.helpers.SubstituteLoggerFactory | ||
import kotlin.io.path.createTempFile | ||
import kotlin.io.path.readText | ||
|
||
class LoggerAdapterTest : FunSpec({ | ||
|
||
test("slf4j logger output") { | ||
val logFactory = SubstituteLoggerFactory() | ||
|
||
val loggerAdapter = LoggerAdapter( | ||
createTempFile().toFile(), | ||
logFactory.getLogger("test"), | ||
"LOG-TAG" | ||
) | ||
|
||
loggerAdapter.error("an error msg") | ||
loggerAdapter.warn("a warn msg") | ||
loggerAdapter.debug("a debug msg") | ||
loggerAdapter.info("an info msg") | ||
loggerAdapter.progress("a progress msg") | ||
|
||
loggerAdapter.errorsCount shouldBe 1 | ||
loggerAdapter.warningsCount shouldBe 1 | ||
|
||
logFactory.eventQueue.map { it.render() }.shouldContainExactly( | ||
"ERROR e: [LOG-TAG] an error msg", | ||
"WARN w: [LOG-TAG] a warn msg", | ||
"DEBUG [LOG-TAG] a debug msg", | ||
"INFO [LOG-TAG] an info msg", | ||
"INFO [LOG-TAG] a progress msg", | ||
) | ||
} | ||
|
||
test("logfile output") { | ||
val logFile = createTempFile() | ||
|
||
LoggerAdapter( | ||
logFile.toFile(), | ||
NOPLogger.NOP_LOGGER, | ||
"LOG-TAG" | ||
).use { loggerAdapter -> | ||
loggerAdapter.error("an error msg") | ||
loggerAdapter.warn("a warn msg") | ||
loggerAdapter.debug("a debug msg") | ||
loggerAdapter.info("an info msg") | ||
loggerAdapter.progress("a progress msg") | ||
|
||
loggerAdapter.errorsCount shouldBe 1 | ||
loggerAdapter.warningsCount shouldBe 1 | ||
} | ||
|
||
logFile.readText() shouldBe """ | ||
|[ERROR] an error msg | ||
|[WARN] a warn msg | ||
|[DEBUG] a debug msg | ||
|[INFO] an info msg | ||
|[PROGRESS] a progress msg | ||
| | ||
""".trimMargin() | ||
} | ||
|
||
}) { | ||
companion object { | ||
private fun SubstituteLoggingEvent.render(): String = buildString { | ||
append("$level") | ||
append(" ") | ||
append(message) | ||
} | ||
} | ||
} |
Oops, something went wrong.