java - 如何仅在春季更改单元测试执行的日志级别
问题描述
我对如何仅更改单元测试执行的日志级别有疑问。
目前,我的应用程序正在以正确的日志级别运行(执行,而不是单元测试),一切都很好,非常高兴。
但是,每次我在任何本地机器上或在我们的 CI 管道上运行单元测试时,我们都会看到以下内容:
10:29:45.274 [main] DEBUG org.springframework.test.util.ReflectionTestUtils - Setting field 'contactPoints' of type [null] on target object [CassandraConfiguration@231f98ef] or target class [class CassandraConfiguration] to value [localhost]
10:29:45.277 [main] DEBUG org.springframework.test.util.ReflectionTestUtils - Setting field 'port' of type [null] on target object [CassandraConfiguration@231f98ef] or target class [class com.apple.pay.cloud.vaxholm.base.configuration.CassandraConfiguration] to value [9042]
和其他调试日志。
什么是“禁用”这些调试日志的正确方法,或者仅针对单元测试“更改日志级别”?
谢谢
解决方案
如果您没有更改您正在使用 logback 的 spring 的默认记录器...
如果是这样的话
在中创建一个logback-test.xml
文件src/test/resources
在该文件中,您应该能够配置您的记录器(很可能是标准输出记录器
就像是:
<configuration>
<include resource="/org/springframework/boot/logging/logback/base.xml"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
推荐阅读
- python - 计算大素数 p 的 a^b mod p
- reactjs - 为什么 useContext() 不返回 Provider 值而是返回初始值?
- python - Python Break 语句结束计算器
- mongodb - Mongodb - 从聚合查找中的子集合中计数
- mysql - 使用 SET 语法将输入作为变量传递时,MySQL 存储过程不返回输出
- node.js - “发送后无法设置标题” Passport js on successredirect
- python - 如何从多个子进程登录到同一个文件
- html - 如何不对 :before 中添加的内容应用悬停效果?css
- git - Git 子模块获取不正确的提交哈希
- coq - 如何证明 le 的所有证明相等?