我有一个 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
.
.
.
如何调整 Hibernate 日志记录级别,说警告?
例如,EclipseLink 让您通过属性 (persistence.xml) 指定级别:
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.logging.level.sql" value="FINE" />
Hibernate 中是否有等效项?
最佳答案
我总是更喜欢使用中央配置文件而不是库的几个特定日志设置来配置日志框架,因为这根本就是使用日志框架的原因之一。
Hibernate 似乎是follow that philosophy并且由于您正在使用 JDK 日志记录 configure the log level with a property file .
关于java - Hibernate:如何调整默认日志记录级别(SJF4J 和 JDK 1.4 记录器)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4394179/