Hibernate:如何调整默认日志记录级别(SJF4J 和 JDK 1.4 记录器)?

发布于 2024-10-07 05:08:52 字数 1967 浏览 8 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遮云壑 2024-10-14 05:08:52

我总是更喜欢使用中央配置文件来配置日志记录框架,而不是库的几个特定日志记录设置,因为这是使用日志记录框架的原因之一。

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.

失去的东西太少 2024-10-14 05:08:52

在我的logging.properties文件中,我设置:

org.hibernate.SQL.level=FINEST // Show SQL statements
org.hibernate.type.level=FINEST // Show the bind parameter values

In my logging.properties file, I set:

org.hibernate.SQL.level=FINEST // Show SQL statements
org.hibernate.type.level=FINEST // Show the bind parameter values
念﹏祤嫣 2024-10-14 05:08:52

阻止 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文