This question already has an answer here:
In my hibernate.cfg.xml, I have the following:
<property name="show_sql">true</property>
In my log4j.xml, I have the following:
<logger name="org.hibernate" additivity="false">
<level value="TRACE"/>
<appender-ref ref="hbn_log"/>
</logger>
<category name="org.hibernate.SQL" additivity="false">
<priority value="TRACE"/>
<appender-ref ref="hbn_log"/>
</category>
<category name="org.hibernate.type" additivity="false">
<priority value="TRACE"/>
<appender-ref ref="hbn_log"/>
</category>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder">
<level value="TRACE"/>
<appender-ref ref="hbn_log"/>
</logger>
<logger name="org.hibernate.event.def.DefaultLoadEventListener" additivity="true">
<level value="all"/>
<appender-ref ref="hbn_log"/>
</logger>
<logger name="org.hibernate.cache.ReadWriteCache" additivity="true">
<level value="all"/>
<appender-ref ref="hbn_log"/>
</logger>
<appender name="hbn_log" class="com.adventnet.management.log.NMSRollingFileAppender">
<param name="File" value="logs/hbn.txt"/>
<param name="MaxFileSize" value="1MB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd MMM yyyy HH:mm:ss:SSS}] %-5c{2}: %m%n"/>
</layout>
<param name="Threshold" value="TRACE"/>
</appender>
In my stdout.txt, I can see that it logs the SQL statement:
[13 Apr 2013 22:03:59:199] SYS_OUT: Hibernate: select this_.EMSID as EMSID195_0_, this_.COUNTER as COUNTER195_0_, this_.TIMESTAMP as TIMESTAMP195_0_, this_.UPDATETYPE as UPDATETYPE195_0_, this_.OBJECTTYPE as OBJECTTYPE195_0_, this_.OBJECTID as OBJECTID195_0_, this_.OBJECT as OBJECT195_0_ from WebNmsDB.UpdateData this_ where this_.EMSID=?
But I want it to also log the parameter for the SQL, and it's not showing it.
Another thing is that the appender is defined to log to hbn.txt, but the SQL statement gets logged to stdout.txt and not hbn.txt. I don't know why that's happening.
Append this config on your log4j.xml
Don't forgot to check your appender's Threadhold level.