-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Hibernate log of SQL goes to stdout
PostPosted: Mon Oct 23, 2006 12:46 pm 
Newbie

Joined: Tue Sep 05, 2006 11:11 am
Posts: 11
I am trying to send all of hibernate logging into a file instead of stdout. By setting up log4j.properties most of hibernate logging goes to the file as expected, except, SQL statements go to stdout no matter what.

I read through the forum and saw references to commons.logging (which caused class not found issues).

Hibernate version:3.1

Here is a portion of log4j.properties


log4j.appender.trcfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.trcfile.File=IEFE.trc
log4j.appender.trcfile.DatePattern='.'yyyyMMdd
log4j.appender.trcfile.layout=org.apache.log4j.PatternLayout
log4j.appender.trcfile.layout.ConversionPattern=%d{yyyyMMdd HH:mm:ss,SSS} %t %m%n

log4j.rootLogger=warn, stdout

log4j.logger.org.hibernate=info, trcfile
log4j.additivity.org.hibernate=false


Is there something wrong or missing with that setup?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 1:09 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
If you've got Hibernate outputting some of the log entries to a file, then all you might want to add the following to your log4j.properties:
Code:
log4j.logger.org.hibernate.SQL=info, trcfile


Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 1:17 pm 
Newbie

Joined: Tue Sep 05, 2006 11:11 am
Posts: 11
Thanks for the quick response. Unfortunately, that does not fix it. The SQL still goes to the console and I continue to see this in my trcfile (IEFE.trc):

Echoing all SQL to stdout


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 10:37 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Set the level to debug on org.hibernate.SQL. Set the "hibernate.show_sql" property to false. I tried this and the SQL was in the file (it was also in the console and I didn't try to stop it)

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 11:16 am 
Newbie

Joined: Tue Sep 05, 2006 11:11 am
Posts: 11
I had tried that before. Setting log level to DEBUG generates much more lines that I want to see.

Adding this to log4j.properties will stop the hibernate debug statements going to the file and console.

log4j.additivity.org.hibernate=false

I am more interested in finding out why the SQL statements continue to go to stdout when in log4j it is set up to go to a file. Maybe it is a feeeeechure :)

Thanks.


Top
 Profile  
 
 Post subject: show_sql property
PostPosted: Tue Dec 05, 2006 5:55 am 
Newbie

Joined: Sat Jul 16, 2005 3:38 am
Posts: 1
Check that the show_sql hibernate property is not getting set to true anyway in your configuration. This will make hibernate log the sql statements to stdout.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 7:31 am 
Newbie

Joined: Tue Sep 05, 2006 11:11 am
Posts: 11
Thanks. But I want to see the SQL so I want show_sql=true. The key is finding a way for the SQL to be displayed in the trace file instead of stdout. It seems Hibernate only sends the SQL to stdout (unless debug level is set to debug which is not desired).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 6:27 am 
Newbie

Joined: Tue Jan 16, 2007 6:22 am
Posts: 1
Location: India
Hi,

I want same behaviour also. I want all the output of hibernate (sql, connection managers etc.) but not on stdout but on seperate file specific for hibernate's logs. I have tried many config but still output is on stdout only.

Anybody found the solution ?
I m using Hibernate Ver : 3.1.3 with Spring 1.2.7 Version


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 7:11 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Sorry guys. The output of this sql lines created by "show-sql" is hard-coded on hibernate:

if ( factory.getSettings().isShowSqlEnabled() ) {
System.out.println( "Hibernate: " + format(sql) );
}

You can not log *this* to the log4j logs...

But you can achieve almost the same using the following:

log4j.appender.trcfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.trcfile.File=IEFE.trc
log4j.appender.trcfile.DatePattern='.'yyyyMMdd
log4j.appender.trcfile.layout=org.apache.log4j.PatternLayout
log4j.appender.trcfile.layout.ConversionPattern=%d{yyyyMMdd HH:mm:ss,SSS} %t %m%n

log4j.rootLogger=warn, stdout

log4j.logger.org.hibernate=info, trcfile
log4j.additivity.org.hibernate=true

log4j.logger.org.hibernate.SQL=debug, trcfile
log4j.additivity.org.hibernate.SQL=true

Let me know if this works...

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:17 pm 
Newbie

Joined: Tue Sep 05, 2006 11:11 am
Posts: 11
Thanks for the response. Hopefully the hibernate developers are watching this forum and can either change that so it is using the logger and not System.out.println() or at least give an explanation of why they chose to do that.

The workaround does not work though. I might be wrong but since it is not using the logger to log the SQL, changing log4j definitions would not have any impact on that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:24 pm 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Sorry, the log4j.properties was wrong. Use:

log4j.appender.trcfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.trcfile.File=IEFE.trc
log4j.appender.trcfile.DatePattern='.'yyyyMMdd
log4j.appender.trcfile.layout=org.apache.log4j.PatternLayout
log4j.appender.trcfile.layout.ConversionPattern=%d{yyyyMMdd HH:mm:ss,SSS} %t %m%n

log4j.rootLogger=warn, stdout

log4j.logger.org.hibernate=info, trcfile
log4j.additivity.org.hibernate=false

log4j.logger.org.hibernate.SQL=debug, trcfile
log4j.additivity.org.hibernate.SQL=false

It should work!

Note that SQL sentence is "logged" in two ways, one to the console and another to the logging system.

(Read http://www.javalobby.org/java/forums/t44119.html)

Regards.

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject: Re: Hibernate log of SQL goes to stdout
PostPosted: Tue Jul 13, 2010 5:02 am 
Newbie

Joined: Sun Jun 06, 2010 10:44 am
Posts: 3
I know it is very old thread but it is common problem facing by many people, so thinking to share my solution.

Use

Code:
<logger name="org.hibernate>
<level value="info"/>
</logger>


in the log4j.xml and

Just add slf4j-log4j12-1.5.2.jar in your classpath if you are using slf4j-api.

Source of Solution: http://ayushsuman.blogspot.com/2010/07/turning-off-hibernate-logging-console.html

Thanks,

Binod Suman


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.