I'm a newbie when it comes to spring so this maybe something simply I'm over looking but I've been trying for hours to no avail. I have spring and hibernate integrated and working however, I want to log the queries to a file so that I can examine them. I'm using log4j for the logging but the issue is I can't get hibernate to write to the file and was hoping to get some clarification.
Here is the sessionFactory bean in applicationContext
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="com.example"/>
</bean>
Log4j configuration
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.home}/logs/my-log-file.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="20MB" />
<param name="MaxBackupIndex" value="2" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{DATE} %c | %msg %n" />
</layout>
</appender>
<appender name="hibernate-rolling" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.home}/logs/hib-example-file.log" />
<param name="Append" value="true" />
<param name="ImmediateFlush" value="true" />
<param name="MaxFileSize" value="20MB" />
<param name="MaxBackupIndex" value="2" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{DATE} %c | %msg %n"/>
</layout>
</appender>
<logger name="org.hibernate.SQL" additivity="false">
<level value="debug" />
<appender-ref ref="hibernate-rolling" />
</logger>
<root>
<priority value="INFO"></priority>
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
Any help is much appreciated?
EDIT:
I have tried the loggers that were provided in that link but that did not cause the queries to be written to the file.