简体   繁体   中英

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.

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

  2. Since Hibernate uses the slf4j facade, you should be able to use the NOPLogger ; see Get a dummy slf4j logger? .

    Replace the log4j-core dependency with this:

     <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. The code snippet above is configuring the java.util.logging logger ...

Look at the javadocs for the log4j classes.

这对我有用..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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