简体   繁体   English

我可以关闭SLF4J SimpleLogger中的日志记录吗?

[英]Can I turn off logging in SLF4J SimpleLogger?

I'm using SLF4J SimpleLogger for unit tests. 我正在使用SLF4J SimpleLogger进行单元测试。 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. 当我以前使用Log4J时,我可以抓住测试中的类的记录器,并在运行测试之前将其级别更改为OFF,然后将其更改回来。 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. 看起来SimpleLogger没有OFF级别,因此最安静的设置是ERROR,当然在调用error()时仍会记录。

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级别的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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