如何在junit中控制日志级别

时间:2017-11-28 17:47:15

标签: java spring spring-boot gradle junit

我正在学习Spring In Action 4th。我读了第2章。

当我在第2章完成第一个演示时,我发现了一些问题。 junit start时有太多的调试信息。

Too much debug info

我不知道如何限制junit的输出。我尝试在src / test / resources文件夹中添加application.yml,但它不起作用。

有人可以给我一些关于如何控制junit中日志信息级别的建议吗?

如果您想查看我的代码,可以从Github下载我的代码。

我的项目使用SpringBoot和Gradle。

1 个答案:

答案 0 :(得分:0)

在src / main / resources中创建application-test.properties 并设置日志记录级别INFO

logging.level.root=INFO

并在Test类中使用@ActiveProfiles(" test")

例如:

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class Chapter2ApplicationTests

此外,如果您希望更改所有配置文件的应用程序级别的日志记录级别,请在application.yml中更改

logging:
  level:
    root: info
soundsystem: info
相关问题