码迷,mamicode.com
首页 > 其他好文 > 详细

log4j.properties打印日志信息(1)

时间:2015-06-26 11:03:54      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:log4j   junit   java   控制台   

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

log4j.properties文件放在src下,系统启动时会默认加载

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=======北京


log4j.properties打印日志信息(1)

标签:log4j   junit   java   控制台   

原文地址:http://blog.csdn.net/u010081710/article/details/46646531

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!