1

I'm having problems with disabling hibernates logging system. I tried creating a log4j.properties file and set the property rootLogger to false but it didn't do anything.

What i get in my console is:

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

How can i disable all the messages to the output console?

I'm using Hibernate 4.2.2

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
Jamie
  • 3,031
  • 5
  • 36
  • 59
  • Might be a duplicate of: http://stackoverflow.com/questions/311408/turning-off-hibernate-logging-console-output?rq=1 –  Jul 04 '15 at 18:18
  • @RC. That's for version 3, I am using 4. Not sure if there is a difference. – Jamie Jul 04 '15 at 18:21
  • In the linked question someone posted some code with jboss logging and I think this is still valid. see also the documentation: http://docs.jboss.org/hibernate/orm/4.3/topical/html/logging/Logging.html –  Jul 04 '15 at 18:23

3 Answers3

1

Try setting the Root Logger to the ERROR level:

log4j.logger.org.hibernate=error

Make sure you have SLF4J and LOG4J in your classpath as Hibernate might fallback to using other logging frameworks instead.

Try adding a breakpoint in org.jboss.logging.LoggerProviders when Hibernate starts to check the Logging provider.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
1

I just had a very similar situation, where I was trying to find a way to disable Hibernate's logging when creating an EntityManagerFactory during the start of my application. It also happened to me that none of the answers I found on StackOverflow work. I'm using Hibernate 5.2.10.Final, which uses jboss-logging-3.3.0.Final.

I had to go to the extreme measure, or hack, of disabling all log messages by getting the "empty-named" java.util.logging.Logger and setting its level to java.util.logging.Level.SEVERE thus:

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

However, as this is the parent of all Loggers, this will also affect any other Loggers you are using. You may want to set the level (back) to another level afterwards.

Renato Montes
  • 19
  • 1
  • 6
0

I had to add the following dependencies in my maven in order to get rid of the logging. I am using Hibernate 4 and Log4j2

  • log4j-api
  • log4j-core
  • log4j-jcl // reverse bridge to log4j v1.x
  • slf4j-simple
  • jboss-logging // without this it did not work

in your log4j2.xml

<Logger name="org.hibernate" additivity="false" level="error"/>

maven POM:

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.5</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.11.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.11.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.2.0.Final</version>
    </dependency>
megloff
  • 1,400
  • 4
  • 27
  • 44