java 关闭休眠日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13500197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Turn off Hibernate logging
提问by
I am using Hibernate for a small demo project. I am using Eclipse and I start the program from within Eclipse, which will print program output to the Eclipse console.
我正在将 Hibernate 用于一个小型演示项目。我正在使用 Eclipse 并从 Eclipse 中启动程序,这会将程序输出打印到 Eclipse 控制台。
It's a plain Java project, no Maven, no Spring, no nothing. I just added the required hibernate libraries to my build path, which also includes jboss-logging-3.1.0.GA (which includes some log4j classes, so I suppose log4j is at work here).
这是一个普通的 Java 项目,没有 Maven,没有 Spring,什么都没有。我刚刚将所需的休眠库添加到我的构建路径中,其中还包括 jboss-logging-3.1.0.GA(其中包括一些 log4j 类,所以我认为 log4j 在这里起作用)。
There are many people asking this question on the web, but none of the proposed solutions work for me.
网上有很多人问这个问题,但没有一个建议的解决方案适合我。
I created a log4j.properties file inside the src directory of my project (so it definately will be on the classpath). The log4j.properties file is copied to the bin directory by Eclipse when the project is being build. It contains one single line:
我在我的项目的 src 目录中创建了一个 log4j.properties 文件(所以它肯定会在类路径上)。Eclipse 在构建项目时将 log4j.properties 文件复制到 bin 目录中。它包含一行:
log4j.logger.net.sf.hibernate=fatal
which I found on the web. I also tried with
我在网上找到的。我也试过
log4j.logger.org.hibernate=fatal
which does not help either.
这也无济于事。
Still I get following console output, which are all info messages (which should not appear as I set the severity to fatal ...):
我仍然得到以下控制台输出,这些都是信息消息(当我将严重性设置为致命时,它不应该出现......):
21.11.2012 19:53:51 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
21.11.2012 19:53:51 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
21.11.2012 19:53:51 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
21.11.2012 19:53:51 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
21.11.2012 19:53:51 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
21.11.2012 19:53:51 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
21.11.2012 19:53:51 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
21.11.2012 19:53:51 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/quellsystem]
21.11.2012 19:53:51 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
21.11.2012 19:53:52 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
21.11.2012 19:53:52 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
21.11.2012 19:53:52 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
I also tried adding -Dlog4j.configuration=log4j.properties to the VM arguments of my Eclipse run configuration. Doesn't help either way ...
我还尝试将 -Dlog4j.configuration=log4j.properties 添加到我的 Eclipse 运行配置的 VM 参数中。没有任何帮助...
回答by Sam Soldatenko
You can use log4j configuration file.
您可以使用 log4j 配置文件。
To be able to use log4j.properties
file add this to your pom.xml
为了能够使用log4j.properties
文件,将此添加到您的pom.xml
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>
To disable logging, you can put this in your src/test/resources/log4j.properties
file
要禁用日志记录,您可以将其放在您的src/test/resources/log4j.properties
文件中
log4j.rootLogger=OFF