简体   繁体   English

将项目更改为 spring 引导后禁用 log4j 不工作

[英]disabling log4j not working after changing project to spring boot

We have always been able to disable logging from our Unit Test via this line我们一直能够通过这条线从我们的单元测试中禁用日志记录

Logger.getLogger(ServiceImpl.class).setLevel(Level.OFF);

However after changing the project to spring boot this no longer works.但是,将项目更改为 spring 引导后,这不再有效。 Logs are written when unit test is ran.运行单元测试时写入日志。
I have also tried adding a log4j2.xml in our test/resources and set the root level to off, but this had no effect either.我也尝试在我们的测试/资源中添加一个 log4j2.xml 并将根级别设置为关闭,但这也没有效果。 How can I disable console output when unit testing?单元测试时如何禁用控制台 output?

as the comment above mentions, logback is being used正如上面的评论提到的,正在使用 logback

created a logback-test file and set root level to off and this resolved the issue创建了一个 logback-test 文件并将根级别设置为关闭,这解决了问题

  <configuration>
  <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
        </layout>
    </appender>

    <root level="off">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

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

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