Note that there are some explanatory texts on larger screens.

plurals
  1. POiBatis, spring, how to log the sql that is executed?
    text
    copied!<p>I am using iBatis with spring framework. I want to log the sql that iBatis executes when I say something like </p> <pre><code>Employee e = (Employee) getSqlMapClientTemplate().queryForObject("emp_sql", emp); </code></pre> <p>The above line will look for "emp_sql" id in the ibatis sql file that I have. And then run the query corresponding to "emp_sql". I want to log this query.</p> <p>I have the following log4j xml properties file.</p> <pre><code>&lt;appender name="sqlLogAppender" class="org.apache.log4j.DailyRollingFileAppender"&gt; &lt;param name="file" value="/disk1/logs/sql.log"/&gt; &lt;param name="datePattern" value="'-'yyyy-MM-dd'.txt'"/&gt; &lt;layout class="org.apache.log4j.PatternLayout"&gt; &lt;param name="ConversionPattern" value="%m %n"/&gt; &lt;/layout&gt; &lt;filter class="org.apache.log4j.varia.LevelRangeFilter"&gt; &lt;param name="LevelMin" value="DEBUG"/&gt; &lt;/filter&gt; &lt;/appender&gt; &lt;logger name="log4j.logger.com.ibatis"&gt; &lt;level value="DEBUG"/&gt; &lt;appender-ref ref="sqlLogAppender"/&gt; &lt;/logger&gt; &lt;logger name="log4j.logger.java.sql.Connection"&gt; &lt;level value="DEBUG"/&gt; &lt;appender-ref ref="sqlLogAppender"/&gt; &lt;/logger&gt; &lt;logger name="log4j.logger.java.sql.PreparedStatement"&gt; &lt;level value="DEBUG"/&gt; &lt;appender-ref ref="sqlLogAppender"/&gt; &lt;/logger&gt; </code></pre> <p>I still cannot get the sql that the ibatis executed. Is there something wrong with the configuration? Should I just say </p> <pre><code>&lt;appender name="sqlLogAppender" class="org.apache.log4j.DailyRollingFileAppender"&gt; &lt;param name="file" value="/disk1/logs/sql.log"/&gt; &lt;param name="datePattern" value="'-'yyyy-MM-dd'.txt'"/&gt; &lt;layout class="org.apache.log4j.PatternLayout"&gt; &lt;param name="ConversionPattern" value="%m %n"/&gt; &lt;/layout&gt; &lt;filter class="org.apache.log4j.varia.LevelRangeFilter"&gt; &lt;param name="LevelMin" value="DEBUG"/&gt; &lt;/filter&gt; &lt;/appender&gt; &lt;logger name="log4j.logger.java.sql"&gt; &lt;level value="DEBUG"/&gt; &lt;appender-ref ref="sqlLogAppender"/&gt; &lt;/logger&gt; </code></pre> <p>Do I have to use p6spy or something else? Or is there something that I can do in the log4j configuration to get the iBatis sql logs?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload