Can't stop Hibernate from writing log to console (log4j.properties is ok)
Asked Answered
B

6

22

I've already set

<property name="show_sql">false</property>

and I have disabled all messages in log4j.properties

But Hibernate write to console with all queries & statements.

Bumpy answered 16/1, 2010 at 12:48 Comment(3)
I'm having the same problem. I've set log4j.logger.org.hibernate=INFO and <property name="show_sql">false</property>, but I still get the hibernate SQL added to my log file. I've searched everything in my project for "show_sql" and "log4j" to find any other references, but there aren't any. Is there another way to turn on hibernate logging?Antedate
Sorry for the noise, but I was wrong -- doing the things I mentioned DO remove all SQL logging. I discovered that a 3rd-party library I am using has this line hard coded in it: System.out.println(hql); Yikes.Antedate
possible duplicate of Can't make hibernate stop showing SQL using Spring JPA Vendor AdapterTransect
O
23

Setting the hibernate.show_sql to true tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.

So even if you set this property to false, make sure that you don't have the following category defined (or configured to use a console appender):

log4j.logger.org.hibernate.SQL=DEBUG

Also, make sure that you don't set the hibernate.show_sql programmatically to true when instancing your Configuration object. Hunt something like this:

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

Note that the setProperty(String propertyName, String value) takes as first parameter the full name of a configuration property i.e. hibernate.show_sql, not just show_sql.

Ostap answered 16/1, 2010 at 18:30 Comment(2)
@Pascal: see my comment to the question. Everything you've suggested, I've looked into. Do you have any other ideas?Antedate
I use logback (plus slf4j) and I added to my logback config file: <logger name="org.hibernate.type" level="ALL" /> <logger name="org.hibernate.SQL" level="WARN" /> <logger name="org.hibernate" level="DEBUG" />Edeline
B
2

HI there, i figured out you can solve this also with this 2 lines in your log4j.properties file.

log4j.logger.org.hibernate = WARN
log4j.logger.org.hibernate = ERROR
Brassie answered 9/12, 2010 at 14:50 Comment(0)
D
1

You adding something like this to log4j.properties?

log4j.logger.org.hibernate = WARN
Despite answered 16/1, 2010 at 17:18 Comment(0)
B
0

It seems very strange, but when Use Eclipse with JUnit Test task, all output still goes to Console (in Eclipse Console window).

But when I use ant command for unit testing, nothing goes to console.

Bumpy answered 18/1, 2010 at 5:54 Comment(0)
C
0

As mentioned before, you need first to set hibernate.show_sql to false. This will prevent hibernate output to console or Tomcat stdout log.

But in order to direct your sql output to another log use this code in log4j.xml file:

<logger name="org.hibernate.SQL" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="hibernate"/>
</logger>

To keep the normal hibernate log level (WARN / ERROR) to console use this code in log4j.xml file:

<category name="org.hibernate">
    <priority value="WARN" />
</category>
Chick answered 31/12, 2015 at 19:31 Comment(0)
E
0

Its simple Just Add dependency to your pom.xml file

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>

And it will disable logging and add put in src/main/resources/log4j.properties file

log4j.rootLogger=OFF

Then you can use it anytime if you want to display log on console then On it or else OFF

Egan answered 25/1, 2018 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.