feat 日志模块

This commit is contained in:
DaxPay
2024-10-12 15:39:16 +08:00
parent 1d6fbd959e
commit 986c3031f4
82 changed files with 3667 additions and 10 deletions

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.bootx.platform</groupId>
<artifactId>bootx-platform-common</artifactId>
<version>3.0.0.beta1</version>
</parent>
<artifactId>common-log</artifactId>
<description>日志模块</description>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,17 @@
package cn.bootx.platform.common.log;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.ComponentScan;
/**
* 日志扫描
*
* @author xxm
* @since 2022/6/6
*/
@ComponentScan
@ConfigurationPropertiesScan
@AutoConfiguration
public class LogAutoConfigurationLogAutoConfiguration {
}

View File

@@ -0,0 +1,44 @@
package cn.bootx.platform.common.log.handler;
import cn.bootx.platform.core.code.CommonCode;
import cn.hutool.core.util.RandomUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.slf4j.MDC;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import java.io.IOException;
/**
* 针对请求生成链路追踪ID
*
* @author xxm
* @since 2021/4/20
*/
@Order(value = Integer.MIN_VALUE)
@Component
@RequiredArgsConstructor
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class LogTraceHeaderHolderFilter extends OncePerRequestFilter {
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
try {
String traceId = RandomUtil.randomString(12);
// 添加普通日志 TraceId
MDC.put(CommonCode.TRACE_ID, traceId);
chain.doFilter(request, response);
}
finally {
MDC.clear();
}
}
}

View File

@@ -0,0 +1 @@
cn.bootx.platform.common.log.LogAutoConfigurationLogAutoConfiguration