Reputation: 47
I have a problem with log4j or Spring or H2 configuration. I can't seem to find the culprit. My problem is that whilst log4j's logging configuration is very strict, I still get unwanted logs from some component in the system.
I use the Spring Framework and Hibernate to access a H2 database. One of those three produces logs that seem to be printed directly to System.out
.
My log output:
12-12 18:41:08 jdbc[2]:
/*SQL */SET DB_CLOSE_DELAY -1;
12-12 18:41:08 jdbc[2]:
/**/Connection conn1 = DriverManager.getConnection("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=Oracle;TRACE_LEVEL_SYSTEM_OUT= 2", "", "");
12-12 18:41:08 jdbc[2]:
/*SQL #:1*/CALL LOCK_MODE();
12-12 18:41:08 database: disconnecting session #2
[main] WARN org.hibernate.internal.util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
As you can see, the only proper logger line is the last one. My log4j configuration is this:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
log4j.logger.org.hibernate=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.h2=WARN
log4j.logger.org.java.sql=WARN
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%t] %-5p %c %x - %m%n
How do I find out who's producing those messages and how do I get him to shut up?
Upvotes: 2
Views: 1040
Reputation: 7344
Not every Java software uses log4j.
In this case H2 generates a trace that can be controlled using slf4j as stated in their documentation in the section "Using Other Logging APIs".
Upvotes: 2