1

I have a spring mvc app running in eclipse with hibernate and slf4j. I would like to turn off hibernate logging in the console because it is burying other console messages that I want to be able to see. How can I turn off hibernate logging?

I have done a number of web searches on this topic, and looked at other postings on stack overflow, but the other postings do not answer my question. For example, the following code from another posting will not compile in eclipse because it gives messages that the methods are not part of the objects, even when I import every possible set of packages for the given object:

    List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
    loggers.add(LogManager.getRootLogger());
    for ( Logger logger : loggers ) {
        logger.setLevel(Level.OFF);
    }

Also, doing a key word search in my workspace for show_sql produced no results, so it seems that I cannot just set hibernate.show_sql to false.

Perhaps the other solutions are for outdated versions of the libraries? I am using eclipse kepler, slf4 1.7.5 and hibernate 4.2.

CodeMed
  • 9,527
  • 70
  • 212
  • 364

3 Answers3

2

In order to turn off the hibernate messages you have to properly configure your logging framework.

Most probably you're using log4j. Configuration of log4j is located either in log4j.xml or log4j.properties

just add something similar to this to the configuration file

log4j.logger.org.hibernate=ERROR
WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
2

If you just want to turn off Hibernate SQL logging in Spring's Petclinic sample application, set jpa.showSql to false in src/main/resources/spring/data-access.properties.

Hope this helps.

Shinichi Kai
  • 4,415
  • 2
  • 21
  • 25
  • +1 and credit for the answer. Thank you for pointing out what should have been obvious to me, but was not. – CodeMed Apr 01 '14 at 21:02
0

This might help, setting "show_sql" to false dynamically in your code.

Configuration cfg = new Configuration().configure().
    .setProperty("hibernate.show_sql", "false");

If not check this post on stackoverflow:

Click here

Community
  • 1
  • 1
Susie
  • 5,038
  • 10
  • 53
  • 74