Wisp Logger takeMessages() unexpectedly consumes all messages
keeferrourke opened this issue · comments
Suppose I have two loggers that I was to check the contents of in a single test method:
// Borrowed and modified from wisp.logging.LogCollectorTest.
@Test fun `check logs happened`() {
val logger = getLogger<LogCollectorTest>()
val logger2 = getLogger<LoggingDummyClass>()
logger.info("A thing happened")
logger2.info("Another thing happened")
assertThat(logCollector.takeMessages(LogCollectorTest::class)).containsExactly("A thing happened")
assertThat(logCollector.takeMessages(LoggingDummyClass::class)).containsExactly("Another thing happened")
}
This test fails because the first call to takeMessages
consumes all the messages in the collector while filtering for the requested ones, leaving no messages left in the collector for the second call.
I would expect that filtering by a KClass should mean that only the log messages matching that class should be taken from the collector. Is this a bad assumption?
Can we make the log collector less destructive so that we can have more powerful assertions against logs?
Hm I guess this is expected behaviour? It's very inconvenient though.
@keeferrourke with the above PR merged, can this issue be closed?
It could be closed, but there was some discussion about migrating to the new non-consuming behaviour as the default.
Not sure if that should be a new issue though?
If relevant/desired, raise a new issue in the Wisp repo.