简体   繁体   中英

Can I turn off logging in SLF4J SimpleLogger?

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?

根据https://jira.qos.ch/browse/SLF4J-332https://www.slf4j.org/news.html SLF4J 1.7.22在SimpleLogger中添加了对OFF级别的支持。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM