无法禁用日志记录消息 [英] Unable to disable logging messages

查看:58
本文介绍了无法禁用日志记录消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难摆脱Spring生成的调试消息(类似于以下消息;其中有数千个条目):

I have some trouble getting rid of debug messages generated by Spring (similiar to the following ones; there are thousands of those entries):

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.

In related questions, there were many suggestions involving log4j, web.xml, ....
However, I am not using any of those - I simply instantiate an AnnotationConfigApplicationContext and start creating beans.

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

In my pom.xml file, there are no references to any logging framework - I only include the spring dependencies:

<!-- 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默认情况下似乎使用公共日志记录",但我未尝试禁用它(如

I read somewhere that Spring seems to use "Commons logging" by default, which I unsuccessfully tried to disable using (as shown in Turn Off Apache Common Logging ):

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

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

In addition, I tried to exclude the commons logging in my pom.xml by adding:

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

但是,仍然没有运气.

接下来,我尝试包括对log4j的依赖关系,希望这将覆盖默认的日志记录.由于消息的格式保持不变,因此这种尝试似乎也没有成功.

Next, I tried including a dependency to log4j, hoping this would override the default logging. As the format of the messages stayed the same, it seems that this attempt was also not successfull.

接下来我可以尝试什么?

What could I try next?

推荐答案

首先:slf4j是否在类路径上?

First: Is slf4j on classpath?

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

SLF4J is another log abstraction for Java, which also could be used together with Spring framework. Many libraries / products have switched to slf4j.

名称中是否存在带有'slf4j'的依赖项?尝试使用mvndependency:tree -Dverbose = true,查看slf4j是否出现.如果是这样,请访问slf4j网站以获取有关其设置的更多信息.

Are there any dependencies with 'slf4j' in its name? Try mvn dependency:tree -Dverbose=true, and look if slf4j appears. If so, look at slf4j website for more information about its setup.

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

Second: which log4j config file is used?

提示检测是否使用了log4j,以及log4j配置文件是否在类路径中: 尝试将属性log4j.debug设置为"true".

Hint to detect if log4j is used, and if a log4j config file is somewhere on the classpath: Try to set property log4j.debug to 'true'.

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

When using mvn exec:java, simply add -Dlog4j.debug=true to command line.

如果这是使用maven surefire插件进行的Junit测试,请尝试在Surefire插件本身中设置systemProperties:

If this is a Junit test with the maven surefire plugin, try set systemProperties in Surefire plugin itself: http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

这篇关于无法禁用日志记录消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆