-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need gelp with logging SQL to file using log4j
PostPosted: Wed Oct 21, 2009 12:47 pm 
Newbie

Joined: Thu Aug 13, 2009 2:51 am
Posts: 3
Hi,

I'm trying to log the hibernate generate SQLs to a file using log4j. I've referenced several posts and website with instruction related to this, but I can't seem to get the SQLs in the file.

I'm using Spring 3.0.0.RC1 & Hibernate 3.3.2

I have set hibernate.show_sql=true, hibernate.use_sql_comments=true & hibernate.format_sql=true

I have the Spring Log4jConfigListener configured before the ContextLoaderListener in my web.xml
Code:
<context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/classes/log4j.properties</param-value>
   </context-param>
   <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
   </listener>
<context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>/WEB-INF/configs/applicationContext.xml</param-value>
      </context-param>
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>


In my log4j.properties I have this
Code:
log4j.logger.org.hibernate.SQL=ALL, HIBERNATE
log4j.additivity.org.hibernate.SQL=false
log4j.logger.org.hibernate.type=INFO, HIBERNATE

log4j.appender.HIBERNATE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.HIBERNATE.File=${webapp.root}/sql.log
log4j.appender.HIBERNATE.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.HIBERNATE.layout=org.apache.log4j.PatternLayout
log4j.appender.HIBERNATE.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n


I see the SQL on the console, but in nothing in the sql.log

Any idea what is missing??

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Need gelp with logging SQL to file using log4j
PostPosted: Mon Oct 26, 2009 10:13 am 
Newbie

Joined: Thu Aug 13, 2009 2:51 am
Posts: 3
Well, after a bit of digging... I got things working the way I want...

The reason I could not log the hibernate SQL to a log file... slf4j-jboss-logging.jar (in JBoss) + slf4j-log4j12.jar (in my web app) resulted in multiple SLF4J log bindings so the SLF4J logging was not bound to any logger... neither JBoss nor Log4J... and since I want my custom log4j to log these SQLs, I removed slf4j-jboss-logging.jar and everything worked as expected... and FYI, I'm using JBoss AS 5.1...

My log4j.properties looks like this
Code:
log4j.appender.HIB=org.apache.log4j.DailyRollingFileAppender
log4j.appender.HIB.File=${webapp.root}/logs/sql.log
log4j.appender.HIB.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.HIB.layout=org.apache.log4j.PatternLayout
log4j.appender.HIB.layout.ConversionPattern=%d %-5p [%c] (%t) %m%n
log4j.appender.HIB.Threshold=TRACE

log4j.logger.org.hibernate.SQL=DEBUG,HIB
log4j.additivity.org.hibernate.SQL=false

log4j.logger.org.hibernate.type=TRACE,HIB


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.