Hibernate suppress info messages

2020-04-12 10:00发布

问题:

So I am not very experience in Java and I am creating a simple test project with Hibernate but I am gettinga lot of INFO messages on the console that I want to suppress. I am creating a Java SE program in Eclipse.

Now as I think I understand it then I need to control this in a log4j.properties file, and I seem to have found the appropiate config to use, but the problem is that it appears that it makes no difference!

My guess is that my log4j.properties file is somehow not being read. But all the details I have found say to place in in the root of my src directory, but it appears not to make any difference. And I have tried placing it in other places in my classpath but all with no luck.

Can somebody help me track down the issue and resolve this?

I had a similar issue last week with a jndi.properties files while using JMS. I eventually resolved that by I am guessing that I am doing something wrong in general. So any tips would be appreciated on where to place config/properties files.

Thanks.

回答1:

log4j logging hierarchy order

OFF
FATAL
ERROR
WARN
INFO
DEBUG
TRACE
ALL

To suppress info messages ,you need to make log4j.properties as

#rootlogger specs
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

set any other logger as OFF