2

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'

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.

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>
<!-- ... --> 

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");

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>

Still no luck, however.

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?

Community
  • 1
  • 1
Matthias
  • 12,053
  • 4
  • 49
  • 91
  • Are you using a config file at all? –  Jan 06 '14 at 20:05
  • @c-qjv0xfi: No, all configuration is done via annotations. Is it neccessary to add one for disabling the logging? – Matthias Jan 06 '14 at 20:12
  • 1
    I just discovered a workaround: http://stackoverflow.com/a/3838108/232175 – Matthias Jan 06 '14 at 20:28
  • @winSharp93 When you tried using log4j, what did you `log4j.properties` look like? For example, did you try to change the logging level of `Spring`? Example: `log4j.logger.org.springframework=ERROR` – user1766760 Jan 06 '14 at 21:23
  • @winSharp93 I believe that should work. –  Jan 06 '14 at 21:24

1 Answers1

1

First: Is slf4j on classpath?

SLF4J is another log abstraction for Java, which also could be used together with Spring framework. Many libraries / products have switched to 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.

Second: which log4j config file is used?

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'.

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

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

Kees van Dieren
  • 1,232
  • 11
  • 15