引入依赖
logback是springboot自带的,要想使用logback处理日志,需要引入一下信息:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
官方推荐使用的xml名字的格式是logback-spring.xml而不是logback.xml,原因是spring后缀的可以使用<springProfile>标签
配置参数格式说明
格式 | 说明 |
---|---|
%-5level | 日志级别(5个字符,不足左对齐) |
%d{yyyy-MM-dd HH:mm:ss.SSS} | 日期 |
%c | 全限定类名 |
%M | method |
%L | 行号 |
%thread | 线程名称 |
%m 或 %msg | 信息 |
%n | 换行 |
%X | 输出所有值 |
%X{testKey} | 输出testKey所对应的value,且无默认值 |
%X{testKey:-} | 输出testKey所对应的value,默认为空 |