Tuesday, May 20, 2008

Showing the sql queries and values for hibernate queries - Log4j configurations

1. Add folowing to hibernate.properties
hibernate.show_sql=true

2. add following to loj4j.xml

<appender name="trace" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="/export/home/log_path/trace.log"/>
<param name="Threshold" value="trace"/>
<param name="DatePattern" value="'.'yyyy-MM-dd-HH'.log'"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{DATE} %-5p [%t] %c{1} - %m%n"/>
</layout>
</appender>

<category name="org.hibernate.type">
<priority value="trace"/>
</category>

<category name="org.hibernate.SQL">
<priority value="trace"/>
</category>


1 comment:

Thilina Anjitha said...

If you want to avoid printing any logs in the logs files, add folowing to the log4j.xml

<category name="org.hibernate">
<priority value="error"/>
</category>