Hibernate:如何调整默认日志记录级别(SJF4J 和 JDK 1.4 记录器)?
我有一个 JavaSE/Hibernate 测试应用程序(基于 shell)。我将以下 JAR 放入项目的 lib 目录中:
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-lang-2.5.jar
dom4j-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
如您所见,我将 SLF4J 与 JDK 1.4 记录器一起使用。当我从 shell 运行我的测试应用程序时,Hibernate 非常详细,因为它默认设置为 INFO 级别:
09.12.2010 02:23:14 org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.6.0.Final
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
09.12.2010 02:23:14 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
09.12.2010 02:23:14 org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.6.0.Final
09.12.2010 02:23:15 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: tld.standalone.bbstats.model.Game
09.12.2010 02:23:15 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity tld.standalone.bbstats.model.Game on table Games
09.12.2010 02:23:15 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: tld.standalone.bbstats.model.Roster
09.12.2010 02:23:15 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity tld.standalone.bbstats.model.Roster on table Rosters
.
.
.
How do I adjustment the Hibernatelogging level, to say WARNING?
例如,EclipseLink 让您通过属性 (persistence.xml) 指定级别:
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.logging.level.sql" value="FINE" />
Hibernate 中是否有等效项?
I have a JavaSE/Hibernate test app (shell-based). I put the following JARs into the project's lib dir:
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-lang-2.5.jar
dom4j-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
As you can see, I'm using SLF4J with the JDK 1.4 logger. When I run my test app from the shell, Hibernate is very verbose because it is set to the INFO level by default:
09.12.2010 02:23:14 org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.6.0.Final
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
09.12.2010 02:23:14 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
09.12.2010 02:23:14 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
09.12.2010 02:23:14 org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.6.0.Final
09.12.2010 02:23:15 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: tld.standalone.bbstats.model.Game
09.12.2010 02:23:15 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity tld.standalone.bbstats.model.Game on table Games
09.12.2010 02:23:15 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: tld.standalone.bbstats.model.Roster
09.12.2010 02:23:15 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity tld.standalone.bbstats.model.Roster on table Rosters
.
.
.
How do I adjust the Hibernate logging level, to say WARNING?
EclipseLink for example let's you specify the level via a property (persistence.xml):
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.logging.level.sql" value="FINE" />
Is there an equivalent in Hibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我总是更喜欢使用中央配置文件来配置日志记录框架,而不是库的几个特定日志记录设置,因为这是使用日志记录框架的原因之一。
Hibernate 似乎遵循这一理念< /a> 并且由于您使用的是 JDK 日志记录 使用属性文件配置日志级别。
I would always prefer to configure the logging framework with a central configuration file instead of several specific logging settings of libraries, because that's one of the reasons to use a logging framework at all.
Hibernate seems to follow that philosophy and since you are using JDK logging just configure the log level with a property file.
在我的logging.properties文件中,我设置:
In my logging.properties file, I set:
阻止 hibernate 如此冗长的最简单方法是将 log4j-over-slf4j.jar 添加到类路径中。这是因为 hibernate 使用 log4j 进行日志记录,当您添加该 jar 时,所有通过 log4j 的日志记录意图将被重定向到 slf4j。
The easiest way to stop hibernate being so verbose is to add
log4j-over-slf4j.jar
to your classpath. That's because hibernate uses log4j for logging, and when you add that jar all the logging intentend to go through log4j will be redirected to slf4j.