Log

默认日志格式

logback

1
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

SpringBoot

1
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:-} [%15.15t] %-40.40logger{39} : %m%n

logback 设置

application.yml

1
2
logging:
config: classpath:logback-${spring.profiles.active}.xml

STDOUT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%5p) %yellow(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

</configuration>

FILE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

<property name="LOG_FILE_PATH" value="./logs"/>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_FILE_PATH}/anthology.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%5p) %boldGreen(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="FILE"/>
</root>

</configuration>