添加 logback 日志框架

This commit is contained in:
xking 2024-07-24 15:31:27 +08:00
parent adfe6eb0ab
commit 86f5244c26
3 changed files with 26 additions and 4 deletions

17
pom.xml
View File

@ -10,11 +10,22 @@
<dependencies> <dependencies>
<!-- apache.logging 与 logback 二选一 -->
<!-- <dependency>-->
<!-- <groupId>org.apache.logging.log4j</groupId>-->
<!-- <artifactId>log4j-slf4j-impl</artifactId>-->
<!-- <version>2.20.0</version>-->
<!-- </dependency>-->
<!--1.3.x 最后一个支持java1.8 的大版本 -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>logback-classic</artifactId>
<version>2.20.0</version> <version>1.3.14</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -41,7 +41,7 @@ public class MDCUtil {
public static void putRequestId() { public static void putRequestId() {
try { try {
MDC.put(REQUEST_ID, UUID.randomUUID().toString()); MDC.put(REQUEST_ID, UUID.randomUUID().toString().replace("-",""));
} catch (RuntimeException ignored) {} } catch (RuntimeException ignored) {}
} }

View File

@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %X [%thread] %-5level %logger{36}.%method:%L %kvp %msg%n</pattern>
<!-- <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread] %logger{32}.%method:%L - %msg%n</pattern>-->
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>