无法禁用日志记录消息

时间:2014-01-06 19:10:53

标签: java spring maven

我在摆脱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 logging”,但我没有成功尝试禁用(如Turn Off Apache Common Logging所示):

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

此外,我尝试通过添加:

来排除登录我的pom.xml的公共区域
<exclusions>
   <!-- Exclude Commons Logging in favor of SLF4j -->
   <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
   </exclusion>
</exclusions>

然而,仍然没有运气。

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

我接下来可以尝试什么?

1 个答案:

答案 0 :(得分:1)

首先:slf4j是否在classpath上?

SLF4J是Java的另一个日志抽象,也可以与Spring框架一起使用。许多图书馆/产品已切换到slf4j。

在名称中是否存在与'slf4j'的依赖关系?尝试mvn依赖: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