How to log Hibernate SQL in to log file?

It is important to log the hibernate sql into log file for debugging purpose.

For this, we need to add a special logger/category named “org.hibernate.SQL” set to “DEBUG” option in log4j.xml

<logger name="org.hibernate.SQL" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="<LOG_APPENDER>" />
</logger>

Or

<category name="org.hibernate.SQL" additivity="false">
    <priority value="debug"/>
    <appender-ref ref="<LOG_APPENDER>" />
</category>

Additivity denotes whether the log needs to be added into the parent logger or not.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: