title: Mybatis log4j how to confiure log4j to print sql log to file
body: <p>i use Spring 4 and MyBatis 3, want to confiure log4j to print sql log such as connection,select, insert, update, delete, statement, preparedStatement, resultSet to log file.</p>
  
  <p>My log4j.properties is as below:</p>
  
  <pre><code>### set log levels ###
  log4j.rootLogger=debug, stdout, log, index, D, I, W, E
  #log4j.rootLogger = debug,error, log, index, D, I, W, E
  log4j.FilePath=${catalina.home}/app_log
  ###  print log to console ###
  log4j.appender.stdout = org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target = System.out
  log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern = %d %p [%c] - &lt;%m&gt;%n
  
  ###  print log to console ###
  log4j.appender.error = org.apache.log4j.ConsoleAppender
  log4j.appender.error.Target = System.out
  log4j.appender.error.layout = org.apache.log4j.PatternLayout
  log4j.appender.error.layout.ConversionPattern = %d %p [%c] - &lt;%m&gt;%n
  
  ### create log to file ###
  log4j.appender.log = org.apache.log4j.DailyRollingFileAppender
  log4j.appender.log.File = ${log4j.FilePath}/all.log
  #log4j.appender.log.MaxFileSize = 1024KB
  log4j.appender.log.Encoding = UTF-8
  log4j.appender.log.Append = true
  log4j.appender.log.layout = org.apache.log4j.PatternLayout
  log4j.appender.log.layout.ConversionPattern= %d %p [%c] - &lt;%m&gt;%n
  log4j.additivity.com.packagename = true 
  
  
  ###  create log on lever debug ###
  log4j.appender.D = org.apache.log4j.RollingFileAppender
  log4j.appender.D.File = ${log4j.FilePath}/debug.log
  log4j.appender.D.MaxFileSize = 1024KB
  log4j.appender.D.Encoding = UTF-8
  log4j.appender.D.Threshold = DEBUG
  log4j.appender.D.layout = org.apache.log4j.PatternLayout
  log4j.appender.D.layout.ConversionPattern= %d %p [%c] - &lt;%m&gt;%n
  log4j.appender.D.MaxBackupIndex = 10
  
  
  ###  create log on lever error ###
  log4j.appender.E = org.apache.log4j.RollingFileAppender
  log4j.appender.E.File = ${log4j.FilePath}/error.log
  log4j.appender.E.MaxFileSize = 1024KB
  log4j.appender.E.Encoding = UTF-8
  log4j.appender.E.Threshold = ERROR
  log4j.appender.E.layout = org.apache.log4j.PatternLayout
  log4j.appender.E.layout.ConversionPattern= %d %p [%c] - &lt;%m&gt;%n
  log4j.appender.E.MaxBackupIndex = 10
  
  
  # If programmed properly the most messages would be at DEBUG 
  # and the least at FATAL.
  
  # Control logging for other open source packages
  log4j.logger.net.sf.navigator=ERROR
  log4j.logger.net.sf.acegisecurity=WARN
  log4j.logger.net.sf.acegisecurity.intercept.event.LoggerListener=WARN
  log4j.logger.org.apache.commons=ERROR
  log4j.logger.org.apache.struts=WARN
  log4j.logger.org.displaytag=ERROR
  log4j.logger.org.springframework=WARN
  log4j.logger.org.apache.velocity=WARN
  log4j.logger.org.springframework.ws.server.MessageTracing=DEBUG
  
  
  # SqlMap logging configuration...
  log4j.logger.com.ibatis=debug,stdout,log
  log4j.logger.com.ibatis.db=debug,stdout,log
  log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug,stdout,log
  log4j.logger.com.ibatis.sqlmap.engine.cache.CacheModel=debug,stdout,log
  log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientImpl=debug,stdout,log
  log4j.logger.com.ibatis.sqlmap.engine.builder.xml.SqlMapParser=debug,stdout,log
  log4j.logger.com.ibatis.common.util.StopWatch=debug,stdout,log
  log4j.logger.org.apache.ibatis=debug,stdout,log
  log4j.logger.org.mybatis.spring=debug,stdout,log
  log4j.logger.org.mybatis.spring.SqlSessionUtils=WARN
  log4j.logger.org.springframework.jdbc.datasource.DataSourceTransactionManager=debug,stdout,log
  
  log4j.logger.org.mybatis.example=TRACE
  
  
  
  log4j.logger.java.sql.Connection=debug
  log4j.logger.java.sql.Statement=debug
  log4j.logger.java.sql.PreparedStatement=debug
  log4j.logger.java.sql.ResultSet=debug
  </code></pre>
  
  <p>it prints sql log in the console, but doesn't print sql log to the log file(such as all.log). can anyone help me? thank you very much!</p>