<dependency> <groupId>org.bgee.log4jdbc-log4j2</groupId> <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId> <version>1.16</version> </dependency>
2.resources文件下新增 log4jdbc.log4j2.properties
文件。
# 将自动加载数据库驱动关闭,因为mysql最新驱动名称为com.mysql.cj.jdbc.Driver,log4jdbc只支持com.mysql.jdbc.Driver log4jdbc.auto.load.popular.drivers=false log4jdbc.drivers=com.mysql.cj.jdbc.Driver log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
3.修改数据库连接配置。
#driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy #url: jdbc:mysql://localhost:3306/oneauth?useUnicode=true&characterEncoding=utf-8 url: jdbc:log4jdbc:mysql://localhost:3306/oneauth?useUnicode=true&characterEncoding=utf-8
<!--设置为OFF,即屏蔽; 留下sqltiming作为INFO级别输出--> <logger name="jdbc.connection" level="OFF"/> <logger name="jdbc.resultset" level="OFF"/> <logger name="jdbc.resultsettable" level="ON"/> <logger name="jdbc.audit" level="OFF"/> <logger name="jdbc.sqltiming" level="INFO"/> <logger name="jdbc.sqlonly" level="OFF"/>
最后效果