Spring Boot 集成 log4j2

转载自:https://blog.csdn.net/laozhou243/article/details/52454800

1、pom.xml加入log4j2,并同时把spring boot默认的logging去掉

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot groupId>
  4. <artifactId>spring-boot-starter-web artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.boot groupId>
  8. <artifactId>spring-boot-starter-logging artifactId>
  9. exclusion>
  10. exclusions>
  11. dependency>
  12. <dependency>
  13. <groupId>org.springframework.boot groupId>
  14. <artifactId>spring-boot-starter-log4j2 artifactId>
  15. dependency>
  16. dependencies>


2、在src/main/resource下新建log4j2.xml,加入对应的配置(可参考http://blog.csdn.net/laozhou243/article/details/52426629)


3、在src/main/resource下新建application.properties文件(该文件用于修改spring boot的一些默认配置),配置log4j2.xml的配置

logging.config=classpath:log4j2.xml

4、添加Logger,用LoggerFactory,不用LogManager,Application是测试类

Logger logger = LoggerFactory.getLogger(Application.class);

你可能感兴趣的:(java)