Springboot使用log4j2日志
1、pom.xml引用依赖
springboot默认是用logback的日志框架的,所以需要排除logback,不然会出现jar依赖冲突的报错
12 12org.springframework.boot 3spring-boot-starter-web 45 6 117 10org.springframework.boot 8spring-boot-starter-logging 913 org.springframework.boot 14spring-boot-starter-log4j2 15
2、配置文件yml文件和xml配置文件:两个文件均在resources下
application.yml部分配置如下
1 mybatis-plus: 2 mapper-locations: classpath:/mapper/**/*.xml 3 type-aliases-package: com.xxx.xxx.entity # 注意:对应实体类的路径 4 5 6 7 8 logging: 9 config: classpath:log4j2.xml 10 level: 11 com.xxx.xxx.dao: DEBUG #这个指定你的dao层,也就是mapper文件的所在包
日志的Level:
1、trace (追踪)
2、debug (调试)
3、info (信息)
4、warn (警告)
5、error (错误)
6、fatal (严重错误)
log4j2.xml配置如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 45 6 7 8 9 10 16 17 1811 12 13 14 15 19 20 74 75 76 7721 22 26 27 2823 24 25 29 31 32 3330 34 35 45 46 4736 37 38 39 42 4340 41 44 48 49 59 60 6150 51 52 53 56 5754 55 58 62 63 7364 65 66 67 70 7168 69 72 78 79 80 81 10782 8483 85 8786 88 9089 91 93 94 9592 96 97 98 99 100 101 106102 103 104 105
参考:https://blog.csdn.net/u012150590/article/details/86601175
https://blog.csdn.net/whl190412/article/details/93487625
https://www.cnblogs.com/suizhikuo/p/15952005.html