gpt4 book ai didi

java - Hibernate 禁用日志记录

转载 作者:行者123 更新时间:2023-11-30 03:21:26 25 4
gpt4 key购买 nike

我在禁用 hibernate 日志系统时遇到问题。我尝试创建一个 log4j.properties 文件并将属性 rootLogger 设置为 false,但它没有执行任何操作。

我在控制台中得到的是:

Jul 04, 2015 8:01:52 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jul 04, 2015 8:01:52 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: Database/hibernate.cfg.xml
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: Database/hibernate.cfg.xml
Jul 04, 2015 8:01:52 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Database/Entities/User.hbm.xml
Jul 04, 2015 8:01:52 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jul 04, 2015 8:01:52 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jul 04, 2015 8:01:52 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jul 04, 2015 8:01:52 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Jul 04, 2015 8:01:52 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Jul 04, 2015 8:01:52 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/gameserver]
Jul 04, 2015 8:01:52 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
Jul 04, 2015 8:01:53 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jul 04, 2015 8:01:53 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Jul 04, 2015 8:01:53 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory

如何禁用输出控制台的所有消息?

我使用的是 Hibernate 4.2.2

最佳答案

我刚刚遇到了非常相似的情况,我试图找到一种方法来在应用程序启动期间创建 EntityManagerFactory 时禁用 Hibernate 日志记录。我还发现,我在 StackOverflow 上找到的答案都不起作用。我使用的是 Hibernate 5.2.10.Final,它使用 jboss-logging-3.3.0.Final。

我不得不采取极端措施,或者黑客,通过获取“空命名”java.util.logging.Logger并将其级别设置为来禁用所有日志消息java.util.logging.Level.SEVERE 因此:

private void disableLogging() {
LogManager logManager = LogManager.getLogManager();
Logger logger = logManager.getLogger("");
logger.setLevel(Level.SEVERE); //could be Level.OFF
}

但是,由于这是所有 Logger 的父级,因此这也会影响您正在使用的任何其他 Logger。之后您可能需要将级别(返回)设置为另一个级别。

关于java - Hibernate 禁用日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31223731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com