log4j的接入和使用
1、在pom文件中配置log4j的依赖
新建配置文件log4j.xml,名字必须是这个
配置内容如下:这样我们执行的sql语句等日志信息就能查看了
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="Encoding" value="UTF-8" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS} %m (%F:%L) \n" />
</layout>
</appender>
<logger name="java.sql">
<level value="debug" />
</logger>
<logger name="org.apache.ibatis">
<level value="info" />
</logger>
<root>
<level value="debug" />
<appender-ref ref="STDOUT" />
</root>
</log4j:configuration>
再次运行测试方法:
看到一些日志信息,包括执行的sql
G:\JavaDev\java1.8\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:J:\Program Files3\idea21.3.3\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar=54665:J:\Program Files3\idea21.3.3\IntelliJ IDEA 2021.3.3\bin" -Dfile.encoding=UTF-8 -classpath "J:\Program Files3\idea21.3.3\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar;J:\Program Files3\idea21.3.3\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit5-rt.jar;J:\Program Files3\idea21.3.3\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit-rt.jar;G:\JavaDev\java1.8\jre\lib\charsets.jar;G:\JavaDev\java1.8\jre\lib\ext\access-bridge-64.jar;G:\JavaDev\java1.8\jre\lib\ext\cldrdata.jar;G:\JavaDev\java1.8\jre\lib\ext\dnsns.jar;G:\JavaDev\java1.8\jre\lib\ext\jaccess.jar;G:\JavaDev\java1.8\jre\lib\ext\jfxrt.jar;G:\JavaDev\java1.8\jre\lib\ext\localedata.jar;G:\JavaDev\java1.8\jre\lib\ext\nashorn.jar;G:\JavaDev\java1.8\jre\lib\ext\sunec.jar;G:\JavaDev\java1.8\jre\lib\ext\sunjce_provider.jar;G:\JavaDev\java1.8\jre\lib\ext\sunmscapi.jar;G:\JavaDev\java1.8\jre\lib\ext\sunpkcs11.jar;G:\JavaDev\java1.8\jre\lib\ext\zipfs.jar;G:\JavaDev\java1.8\jre\lib\jce.jar;G:\JavaDev\java1.8\jre\lib\jfr.jar;G:\JavaDev\java1.8\jre\lib\jfxswt.jar;G:\JavaDev\java1.8\jre\lib\jsse.jar;G:\JavaDev\java1.8\jre\lib\management-agent.jar;G:\JavaDev\java1.8\jre\lib\resources.jar;G:\JavaDev\java1.8\jre\lib\rt.jar;J:\Study\SSM\ssm23\mybatis_helloworld\target\test-classes;J:\Study\SSM\ssm23\mybatis_helloworld\target\classes;C:\Users\Administrator\.m2\repository\org\mybatis\mybatis\3.5.7\mybatis-3.5.7.jar;C:\Users\Administrator\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Administrator\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\8.0.30\mysql-connector-java-8.0.30.jar;C:\Users\Administrator\.m2\repository\com\google\protobuf\protobuf-java\3.19.4\protobuf-java-3.19.4.jar;C:\Users\Administrator\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.wjw.mybatis.test.MyBatisTest,testInsert
DEBUG 02-22 00:45:21,391 ==> Preparing: insert into t_user values(null,'admin','123456',23,'男','[email protected]') (BaseJdbcLogger.java:137)
DEBUG 02-22 00:45:21,426 ==> Parameters: (BaseJdbcLogger.java:137)
DEBUG 02-22 00:45:21,471 <== Updates: 1 (BaseJdbcLogger.java:137)
结果:1
Process finished with exit code 0
标签:jre,lib,java1.8,JavaDev,jar,ssm,ext,23001,log4j
From: https://www.cnblogs.com/wjw-blog/p/17143024.html