1 <settings> 2 <setting name="logImpl" value="STDOUT_LOGGING"/> 3 </settings>
1 <dependency> 2 <groupId>log4j</groupId> 3 <artifactId>log4j</artifactId> 4 <version>1.2.17</version> 5 </dependency>
1 <settings> 2 <setting name="logImpl" value="LOG4J"/> 3 </settings>
1 #将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码 2 log4j.rootLogger=DEBUG,console,file 3 4 #控制台输出的相关设置 5 log4j.appender.console = org.apache.log4j.ConsoleAppender 6 log4j.appender.console.Target = System.out 7 log4j.appender.console.Threshold=DEBUG 8 log4j.appender.console.layout = org.apache.log4j.PatternLayout 9 log4j.appender.console.layout.ConversionPattern=[%c]-%m%n 10 11 #文件输出的相关设置 12 log4j.appender.file = org.apache.log4j.RollingFileAppender 13 log4j.appender.file.File=./log/wzh.log 14 log4j.appender.file.MaxFileSize=10mb 15 log4j.appender.file.Threshold=DEBUG 16 log4j.appender.file.layout=org.apache.log4j.PatternLayout 17 log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n 18 19 #日志输出级别 20 log4j.logger.org.mybatis=DEBUG 21 log4j.logger.java.sql=DEBUG 22 log4j.logger.java.sql.Statement=DEBUG 23 log4j.logger.java.sql.ResultSet=DEBUG 24 log4j.logger.java.sql.PreparedStatement=DEBUG
1 import edu.ustc.wzh.pojo.User; 2 import edu.ustc.wzh.utils.MybatisUtils; 3 import org.apache.ibatis.session.SqlSession; 4 import org.apache.log4j.Logger; 5 import org.junit.Test; 6 7 public class UserMapperTest { 8 9 //注意导包:org.apache.log4j.Logger 10 static Logger logger = Logger.getLogger(UserMapperTest.class); 11 12 @Test 13 public void selectUser() { 14 15 logger.info("info:进入selectUser方法"); 16 logger.debug("debug:进入selectUser方法"); 17 logger.error("error: 进入selectUser方法"); 18 19 SqlSession session = MybatisUtils.getSession(); 20 21 UserMapper mapper = session.getMapper(UserMapper.class); 22 23 User user = mapper.getUserById(1); 24 System.out.println(user); 25 26 session.close(); 27 } 28 29 }
原文:https://www.cnblogs.com/zhihaospace/p/12297636.html