无垃圾机制
在稳态日志记录期间,Log4j 2 在独立应用程序中是无垃圾的,在Web应用程序中是低垃圾。这减少了垃圾收集器的压力,并且可以提供更好的响应性能。
引用依赖
在一般项目中使用Log4j2至少需要引用log4j-api-2.x
和log4j-core-2.x
这两个jar包。
org.apache.logging.log4j
log4j-core
2.12.0
org.apache.logging.log4j
log4j-api
2.12.0
在spring boot项目中使用Log4j2
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-log4j2
小编在使用中遇到一些坑,同时引入spring-boot-starter和spring-boot-starter-web依赖时,需要在spring-boot-starter中排除spring-boot-starter-logging依赖,因为spring-boot-starter-web依赖于spring-boot-starter,根据Maven依赖关系,在spring-bo