简体   繁体   English

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

[英]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.

相关问题 具有JDK Logger的SLF4J日志记录接口 - SLF4J logging interface with JDK Logger 如何避免在log4j记录器中进行Hibernate和JDBC登录 - How to avoid Hibernate and JDBC logging in log4j logger slf4j-jdk14 记录器忽略级别配置 - slf4j-jdk14 logger ignores level configuration slf4j记录器信息级别未在Apache Tomcat中记录 - slf4j logger Info level not logging in Apache Tomcat 您如何在会话级别调整Java中的Sybase优化器设置? - How do you adjust Sybase optimizer settings in Java at the session level? Log4j、commons-logging、JDK-Logging 和 SLF4J 是如何相互关联的? - How do Log4j, commons-logging, JDK-Logging and SLF4J relate to each other? 如何在Hibernate4中更改日志记录级别? - How do I change logging level in Hibernate4? 如何让google guice注入一个自定义记录器,比如一个commons-logging或log4j logger - How do I get google guice to inject a custom logger, say a commons-logging or log4j logger 开发插件时如何配置intellij插件openapi.diagnostic.Logger CONSOLE日志级别 - How do Configure the intellij plugin openapi.diagnostic.Logger CONSOLE logging level when developing a Plugin 你如何在 Tess4j 中禁用登录? - How do you disable logging in Tess4j?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM