Suppressing INFO messages for Hibernate

左心房为你撑大大i 提交于 2020-01-05 05:43:08

问题


I am looking for a solution for suppressing the INFO messages with Hibernate. I tried the instructions given in the following Stackoverflow post, but to no avail:
Hibernate suppress info messages

My output continues to spit out the INFO messages, despite implementing the suggested change.


I am using Eclipse as my IDE and I have a Maven parent project, with multiple child module projects.

Previously I did not have a log4j.properties file in my project but now I have created one, at the same location where I have my hibernate.cfg.xml file i.e. src/test/resources of the child Maven module.

The contents of my log4j.properties file are as follows:

# Source: https://stackoverflow.com/questions/11723030/hibernate-suppress-info-messages
#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

Following the tip from @TestoTestini, I added log4j as a dependency in my child Maven module pom.xml. It was only after that step that the log4j.properties file that I had added earlier seemed to take effect. However, I am still working on suppressing the messages with the Hibernate tag.


回答1:


I think now you have now to add the configuration for Hibernate, I use

log4j.logger.org.hibernate=WARN
# use this to not see the [deprecated DTD] message from Hibernate 
log4j.logger.org.hibernate.orm.deprecation=ERROR
# use this to not see the "no cache configuration" warning
log4j.logger.org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory=ERROR
# This is very important, otherwise db creation errors go silent
log4j.logger.org.hibernate.tool.hbm2ddl=DEBUG

ah I see now you already use ERROR as root logger level so maybe your configuration file is not being read, which version of Hibernate are you using ?

Maybe you have an other log library in the classpath like JBoss LogManager or Log4j 2 ? In that case they might be picked up in place of Log4j



来源:https://stackoverflow.com/questions/59417838/suppressing-info-messages-for-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!