盒子
盒子
文章目录
  1. 参考
  2. 二 yml配置

spring boot + gradle + yml 配置 log4j2

参考

springboot log4j2配置,使用gradle构建

在 gradle 中引入 log4j2,并移除 spring boot 默认 logger。

引入不提。

移除:

1
2
3
4
5
configurations {
providedRuntime
// remove default logger
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}

二 yml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#log4j2
Configuration:
status: warn

Properties: # 定义变量
Property:
- name: log.path
value: d:\\tmp\\logs
- name: project.name
value: spring-boot-log

Appenders:
Console: #输出到控制台
name: CONSOLE
target: SYSTEM_OUT
ThresholdFilter:
level: trace
onMatch: ACCEPT
onMismatch: DENY
PatternLayout:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"

# 输出到文件,超过128MB归档
RollingFile:
- name: ROLLING_FILE
ignoreExceptions: false
fileName: ${log.path}/${project.name}.log
filePattern: "${log.path}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz"
PatternLayout:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"
Policies:
SizeBasedTriggeringPolicy:
size: "128 MB"
DefaultRolloverStrategy:
max: 1000

Loggers:
Root:
level: info
AppenderRef:
- ref: CONSOLE
- ref: ROLLING_FILE
Logger: # 为com.xjj包配置特殊的Log级别,方便调试
- name: com.test.dao
additivity: false
level: debug
AppenderRef:
- ref: CONSOLE
- ref: ROLLING_FILE