Can't turn off debug logging for Wiremock
我在Spring Boot应用程序中使用Wiremock进行测试。我似乎无法使日志记录不输出所有调试日志,这使我的测试非常冗长。
我看到它在启动时使用SLF4J:
DEBUG wiremock.org.eclipse.jetty.util.log - Logging to Logger[wiremock.org.eclipse.jetty.util.log] via wiremock.org.eclipse.jetty.util.log.Slf4jLog
但是尝试通过
在我的application.properties中对其进行配置
logging.level.wiremock.org.eclipse=WARN
没有效果,我还设置了
logging.level.com.github.tomakehurst.wiremock=WARN
但同样,没有效果。由于我使用的是
中进行配置
1 2 3 4 5 | <?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <logger name="wiremock.org.eclipse" level="INFO"/> </configuration> |
同样,我没有做任何事情来阻止Wiremock记录调试级别。我想念什么?
好吧Ive遇到了这个问题,终于解决了。
您需要配置3种不同的记录器
-
Eclipse记录器
wiremock.org.eclipse -
WireMock 处的Wiremock通知程序 -
"/" 上的serverlet记录器或记录器所在的位置。 -
在
com.github.tomakehurst.wiremock 处记录的Wiremock代码
我发现bootstrap.yml不会影响这些记录器,因此您需要将它们放在/ src / test / resources文件夹的
具有以下条目。
1 2 3 4 5 6 | <!-- Turning down the wiremock logging --> <logger name="com.github.tomakehurst.wiremock" level="WARN"/> <logger name="wiremock.org" level="ERROR"/> <logger name="WireMock" level="WARN"/> <!-- wiremock has per endpoint servlet logging --> <logger name="/" level="WARN"/> |
如果要以编程方式实现此目的,并且将SLF4J与Logback结合使用(Spring Boot 2.2中的默认设置),只需执行以下操作:
1 2 | ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("wiremock").setLevel(Level.OFF); ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("WireMock").setLevel(Level.OFF); |
(使用WireMock 2.25)
一个快速的解决方法是更改??
这当然有副作用;这会影响所有日志记录;但又脏又快。