[英]Hibernate: how do you adjust the default logging level (SJF4J and JDK 1.4 logger)?
I have a JavaSE/Hibernate test app (shell-based). 我有一个JavaSE / Hibernate测试应用程序(基于shell)。 I put the following JARs into the project's lib dir: 我将以下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
As you can see, I'm using SLF4J with the JDK 1.4 logger. 如您所见,我正在使用带有JDK 1.4记录器的SLF4J。 When I run my test app from the shell, Hibernate is very verbose because it is set to the INFO level by default: 当我从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 adjust the Hibernate logging level, to say WARNING? 如何调整Hibernate日志记录级别,说警告?
EclipseLink for example let's you specify the level via a property (persistence.xml): 例如EclipseLink让你通过属性指定级别(persistence.xml):
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.logging.level.sql" value="FINE" />
Is there an equivalent in Hibernate? Hibernate中有等价的吗?
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 . Hibernate似乎遵循这一理念 ,因为您使用JDK日志记录只需使用属性文件配置日志级别 。
In my logging.properties file, I set: 在我的logging.properties文件中,我设置:
org.hibernate.SQL.level=FINEST // Show SQL statements
org.hibernate.type.level=FINEST // Show the bind parameter values
The easiest way to stop hibernate being so verbose is to add log4j-over-slf4j.jar
to your classpath. 阻止hibernate如此冗长的最简单方法是将log4j-over-slf4j.jar
添加到类路径中。 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. 那是因为hibernate使用log4j进行日志记录,当你添加该jar时,所有通过log4j的日志记录都会被重定向到slf4j。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.