Spring Boot 集成 log4j2

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

[html]  view plain  copy
  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> <!-- 引入log4j2依赖 -->  
  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是测试

[java]  view plain  copy
  1. Logger logger = LoggerFactory.getLogger(Application.class);  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值