【问题标题】:Why is Spring INFO logging to Standard Error?为什么 Spring INFO 记录到标准错误?
【发布时间】:2011-05-12 11:16:14
【问题描述】:

我有许多数据库集成测试使用以下注释进行事务回滚:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:ApplicationContext-DAOs.xml"})
@Transactional

测试通过了,但是当我运行它们时,Spring 认为有必要在 INFO 级别记录标准错误!它记录以下内容:

19/11/2010 16:49:11 org.springframework.test.context.TestContextManager
  retrieveTestExecutionListeners
INFO: @TestExecutionListeners is not present for class [class my.SomeDAOTest]:
  using defaults.
etc for many, many lines ...

我在哪里关闭它?

【问题讨论】:

    标签: java spring logging stderr standard-error


    【解决方案1】:

    您可以使用 log4j 隐藏它。在您的 log4j.xml 中,为 spring 设置一个记录器以警告(或错误)。

    <logger name="org.springframework">
        <level value="warn"/>
    </logger>
    

    【讨论】:

      【解决方案2】:

      Spring 核心正在使用 apache commons 日志记录。为了配置远离默认行为(写入标准错误),我必须为我的特定框架使用桥组件。

      我使用的是 Log4j2,所以一旦我添加了从 apache commons 到 log4j2 的桥,那么 spring core 就会尊重我的设置。

      <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-jcl</artifactId>
          <version>2.11.2</version>
      </dependency>
      

      【讨论】:

        猜你喜欢
        • 2019-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-05
        相关资源
        最近更新 更多