Spring Boot 集成 log4j2

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

[html]  view plain  copy
  1. <dependencies>  
  2.     <dependency>  
  3.         <groupId>org.springframework.bootgroupId>  
  4.         <artifactId>spring-boot-starter-webartifactId>  
  5.         <exclusions>  
  6.             <exclusion>  
  7.                 <groupId>org.springframework.bootgroupId>  
  8.                 <artifactId>spring-boot-starter-loggingartifactId>  
  9.             exclusion>  
  10.         exclusions>  
  11.     dependency>  
  12.     <dependency>   
  13.         <groupId>org.springframework.bootgroupId>  
  14.         <artifactId>spring-boot-starter-log4j2artifactId>  
  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是测试类

[java]  view plain  copy
  1. Logger logger = LoggerFactory.getLogger(Application.class);  

你可能感兴趣的:(Spring,Boot,ELK)