log4j.properties
log4j.rootLogger=debug,stdout,logfile ### 把日志信息输出到控制台 ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.Target=System.err log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout ### 把日志信息输出到文件:jbit.log ### log4j.appender.logfile=org.apache.log4j.FileAppender log4j.appender.logfile.File=D:/test.log log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %F %p %m%n ###显示SQL语句部分 log4j.logger.com.ibatis=DEBUG log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG log4j.logger.org.mybatis=DEBUG log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG log4j.logger.java.sql.ResultSet=DEBUG
junit测试代码
package dao; import java.io.IOException; import org.apache.log4j.PropertyConfigurator; import org.junit.Test; import com.dao.AddressMapper; import com.model.Address; import com.util.BeanFactoryUtil; public class AddressMapperTest { @Test public void addressMapperTest() throws IOException{ //可以手动加载 //PropertyConfigurator.configure(UserMapperTest.class.getClassLoader().getResource("log4j.properties")); AddressMapper addressMapper=(AddressMapper)BeanFactoryUtil.getInstance().getBean("addressMapper"); Address address=addressMapper.getAddressByAid(4); System.err.println("address======="+address.getAddress()); } }
[26 10:08:52,117 DEBUG] [main] sql.PreparedStatement - ==> Executing: select * from address WHERE aid=?
[26 10:08:52,118 DEBUG] [main] sql.PreparedStatement - ==> Parameters: 4(Integer)
[26 10:08:52,131 DEBUG] [main] sql.ResultSet - <== Columns: aid, address, postCode, ownerid
[26 10:08:52,132 DEBUG] [main] sql.ResultSet - <== Row: 4, 北京, 010, null
[26 10:08:52,133 DEBUG] [main] spring.SqlSessionUtils - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8dcd5d]
[26 10:08:52,134 DEBUG] [main] datasource.DataSourceUtils - Returning JDBC Connection to DataSource
address=======北京
原文地址:http://blog.csdn.net/u010081710/article/details/46646531