简体   繁体   English

我们如何禁用休眠日志?

[英]How can we disable the hibernate logs?

I am working on Hibernate project, But I have to write the logs into a file then both will combined(Hibernate log added in file) How can we disable the hibernate logs.我正在研究 Hibernate 项目,但我必须将日志写入一个文件,然后两者将合并(在文件中添加 Hibernate 日志)我们如何禁用 Hibernate 日志。

<dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.1</version> 
</dependency>

Here are two approaches:这里有两种方法:

  1. Setting the logging level to NONE should turn off all logging.将日志记录级别设置为 NONE 应关闭所有日志记录。

  2. Since Hibernate uses the slf4j facade, you should be able to use the NOPLogger ;由于 Hibernate 使用slf4j外观,您应该能够使用NOPLogger see Get a dummy slf4j logger?请参阅获取虚拟 slf4j 记录器? . .

    Replace the log4j-core dependency with this:用这个替换log4j-core依赖项:

     <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>1.7.30</version> </dependency>

I've used this but its not working for me:我用过这个,但它对我不起作用:

 java.util.logging.Logger.getLogger("org.hibernate") .setLevel(java.util.logging.Level.OFF);

Yea, that won't work.是的,那行不通。 According the the dependency in your question, you have selected the log4j as the backend.根据您问题中的依赖项,您选择了log4j作为后端。 The code snippet above is configuring the java.util.logging logger ...上面的代码片段正在配置java.util.logging记录器......

Look at the javadocs for the log4j classes.查看 log4j 类的 javadoc。

这对我有用..

static { // Initialized log4j2 Property and disable hibernate log Configurator.initialize("LOGS", "Projects/log4j.properties"); Configurator.setLevel("org.hibernate", org.apache.logging.log4j.Level.OFF); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM