Spring Boot日志配置

日志体系

Spring Boot 使用commons-logging作为日志接口,目前支持Log4J2、Logback和JUL( Java Util Logging) 三种实现方式,如下图所示:
这里写图片描述

spring-boot-starter-logging

作用: 使用Logback日志框架;
实现原理:

  1. 如果存在slf4j接口,则将其桥接到commons-logging;
  2. 使用Logback作为日志实现框架;

这里写图片描述

这里写图片描述

spring-boot-starter-log4j

作用: 使用Log4J日志框架;
实现原理:

  1. 如果存在slf4j接口,则将其桥接到commons-logging;
  2. 使用Log4J作为日志实现框架;
    这里写图片描述
    这里写图片描述

spring-boot-starter-log4j2

作用: 使用Log4J2日志框架;
使用配置: 需要将默认的logback排除,同时引入log4j2,如下:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-logging</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

日志的定制

在这里插入图片描述

spring-boot相关日志配置

在这里插入图片描述

参考:

  1. Spring Boot官网:https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/reference/htmlsingle/#boot-features-logging;
  2. slf4j官网:https://www.slf4j.org/legacy.html;
  3. https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#howto-configure-log4j-for-logging;
  4. SpringBoot 默认属性列表:https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值