Question

I'm using SLF4J SimpleLogger for unit tests. Due to external factors, it would be challenging to change log providers.

The class under test grabs a logger from the owning framework to record errors. The problem is that when I test an error condition, I wind up with a big scary error message in the test logs, even though the test passes. I think this is a Bad Thing.

When I used to use Log4J, I could grab the logger for the class under test and change its level to OFF before running the test, then change it back. It looks like SimpleLogger doesn't have an OFF level, so the quietest setting would be ERROR, which of course still logs when error() is called.

Is there a better way to do this? Is it even possible?

Was it helpful?

Solution

According to https://jira.qos.ch/browse/SLF4J-332 and https://www.slf4j.org/news.html SLF4J 1.7.22 added support for OFF level in SimpleLogger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top