禁止休眠的INFO消息 [英] Suppressing INFO messages for Hibernate

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

问题描述

我正在寻找一种使用Hibernate抑制INFO消息的解决方案.我尝试了以下Stackoverflow帖子中给出的说明,但无济于事:
休眠禁止显示信息消息

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

尽管实施了建议的更改,我的输出仍继续吐出INFO消息.

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

我正在使用Eclipse作为我的IDE,并且我有一个Maven父项目,其中有多个子模块项目.

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

以前,我的项目中没有log4j.properties文件,但现在我在拥有我的hibernate.cfg.xml文件的位置(即子Maven模块的src/test/resources)的同一位置创建了一个文件.

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.

我的log4j.properties文件的内容如下:

# 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


根据@TestoTestini的技巧,我在子Maven模块pom.xml中添加了log4j作为依赖项.只是在执行此步骤之后,我之前添加的log4j.properties文件才似乎生效.但是,我仍在努力抑制带有Hibernate标记的消息.


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.

推荐答案

我认为现在您必须为Hibernate添加配置,我使用

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

啊,我现在看到您已经使用ERROR作为root记录程序级别,因此也许您的配置文件没有被读取,您正在使用哪个版本的Hibernate?

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 ?

也许您在类路径中还有另一个日志库,例如JBoss LogManager或Log4j 2?在这种情况下,可以代替Log4j来获取它们

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

这篇关于禁止休眠的INFO消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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