gpt4 book ai didi

java - 无法禁用日志消息

转载 作者:太空宇宙 更新时间:2023-11-04 07:08:39 25 4
gpt4 key购买 nike

我在摆脱 Spring 生成的调试消息时遇到了一些麻烦(类似于以下消息;有数千个这样的条目):

19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'propertyPlaceholderConfigurer'
19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'propertyPlaceholderConfigurer'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'appConfig'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'appConfig'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'appConfig' to allow for resolving potential circular references
19:58:08.384 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'appConfig'

相关问题中,有很多建议涉及log4j、web.xml、...
但是,我没有使用其中任何一个 - 我只是实例化一个 AnnotationConfigApplicationContext 并开始创建 bean。

在我的 pom.xml 文件中,没有对任何日志记录框架的引用 - 我只包含 spring 依赖项:

<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- ... -->
<artifactId>spring-tx</artifactId>
<!-- ... -->
<artifactId>spring-boot-starter</artifactId>
<!-- ... -->
<artifactId>spring-web</artifactId>
<!-- ... -->

我在某处读到,Spring 似乎默认使用“Commons 日志记录”,但我没有成功地尝试禁用它(如 Turn Off Apache Common Logging 所示):

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

此外,我尝试通过添加以下内容来排除 pom.xml 中的公共(public)日志记录:

<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>

但是仍然没有运气。

接下来,我尝试包含对 log4j 的依赖项,希望这会覆盖默认日志记录。由于消息的格式保持不变,看来这次尝试也没有成功。

接下来我可以尝试什么?

最佳答案

第一:slf4j 是否在类路径上?

SLF4J是Java的另一种日志抽象,也可以与Spring框架一起使用。许多库/产品已转向 slf4j。

名称中是否存在包含“slf4j”的依赖项?尝试 mvn dependency:tree -Dverbose=true,然后查看是否出现 slf4j。如果是这样,请访问 slf4j 网站以获取有关其设置的更多信息。

第二:使用哪个 log4j 配置文件?

提示检测是否使用了 log4j,以及 log4j 配置文件是否位于类路径中的某个位置:尝试将属性 log4j.debug 设置为“true”。

使用 mvn exec:java 时,只需在命令行中添加 -Dlog4j.debug=true 即可。

如果这是使用 maven Surefire 插件的 Junit 测试,请尝试在 Surefire 插件本身中设置 systemProperties:http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

关于java - 无法禁用日志消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20957422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com