julian
04/05/2022, 2:09 AMJim
04/05/2022, 9:08 PMobject ProjectConfig : AbstractProjectConfig() {
override val logLevel: LogLevel = LogLevel.Warn
override fun extensions(): List<Extension> = listOf(
object : LogExtension {
override suspend fun handleLogs(testCase: TestCase, logs: List<LogEntry>) {
logs.forEach { println(it.level.name + " - " + it.message) }
}
}
)
class TestsWithLogging : FunSpec({
test("foo") {
warn { "bar" }
}
test("foo2") {
warn { "barbaz" }
warn { "bloop" }
error { "boom" }
}
Jim
04/05/2022, 9:08 PMjulian
04/06/2022, 8:56 PMJim
04/06/2022, 8:56 PMJim
04/06/2022, 9:01 PMJim
04/06/2022, 9:01 PMjulian
04/06/2022, 9:17 PMJim
04/06/2022, 9:18 PMjulian
04/06/2022, 9:27 PMerror { "boom" }
to error("boom")
.Jim
04/06/2022, 9:28 PMjulian
04/06/2022, 9:35 PMpublic inline fun error(message: Any): Nothing = throw IllegalStateException(message.toString())
error { "boom" }
produced this
() -> kotlin.String
java.lang.IllegalStateException: () -> kotlin.String
whereas
error("boom")
produces this
boom
java.lang.IllegalStateException: boom
Jim
04/06/2022, 9:36 PMjulian
04/06/2022, 9:36 PMerror
implementation missing?Jim
04/06/2022, 9:37 PMjulian
04/06/2022, 9:49 PMerror
I was using didn't even need to be imported - it's from kotlin.Preconditions
. It got picked up by default.Big Chungus
04/12/2022, 4:46 PMtasks {
withType<Test>().configureEach {
systemProperty("kotest.framework.loglevel", "info")
}
}
I've also verified that sys prop is indeed visible from test scope, however no info logs show up in gradle test output in intellij
@Jim any clues? Has anyone actually managed to get this working?Jim
04/12/2022, 4:47 PMBig Chungus
04/12/2022, 4:47 PMBig Chungus
04/12/2022, 4:55 PMBig Chungus
04/12/2022, 5:02 PMBig Chungus
04/12/2022, 5:03 PMkotest.framework.loglevel
sys property doesn't seem to do anything as I'm still expected to filter the logs in the extensionBig Chungus
04/12/2022, 5:09 PMobject KotestConfig : AbstractProjectConfig() {
override val logLevel: LogLevel
get() = System.getProperty("kotest.framework.loglevel")?.let(LogLevel::from) ?: LogLevel.Warn
override fun extensions(): List<Extension> = listOf(
object : LogExtension {
override suspend fun handleLogs(testCase: TestCase, logs: List<LogEntry>) {
logs
.filter { it.level >= logLevel }
.forEach { println(it.message) }
}
}
)
}
Jim
04/14/2022, 2:53 AMBig Chungus
04/14/2022, 8:32 AMJim
04/14/2022, 6:07 PMjulian
04/18/2022, 11:31 PM.filter { it.level >= logLevel }
. I think the logs are pre-filtered by logLevel
before they're passed to handleLogs
.Jim
04/18/2022, 11:32 PMBig Chungus
04/18/2022, 11:57 PMJim
04/18/2022, 11:57 PMjulian
04/23/2022, 9:35 PMfoo is excluded by test filter(s): Excluded by test path filter: 'foo2'
when running TestsWithLogging
.
Does Jim's solution get rid of this noise for others? Is it just me?Jim
04/23/2022, 9:39 PMjulian
04/23/2022, 9:41 PMLogExtension
Is there another way to control it?Jim
04/23/2022, 9:42 PMjulian
04/23/2022, 9:46 PMjulian
04/23/2022, 10:06 PMf:
and run the spec itself, I don't get the noise.
That's fine for my purposes.Jim
04/23/2022, 10:07 PM