style: 优化部分代码及注释格式
This commit is contained in:
parent
c03c082d2e
commit
8fe85e3a90
@ -108,7 +108,7 @@
|
||||
<artifactId>continew-starter-json-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--轻量级的分布式日志标记追踪神器-->
|
||||
<!-- TLog(轻量级的分布式日志标记追踪神器) -->
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>tlog-web-spring-boot-starter</artifactId>
|
||||
|
@ -16,16 +16,11 @@
|
||||
|
||||
package top.charles7c.continew.admin.common.config.properties;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.wf.captcha.*;
|
||||
|
||||
/**
|
||||
* 验证码配置属性
|
||||
*
|
||||
|
@ -18,24 +18,38 @@ package top.charles7c.continew.admin.common.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* TLog 配置属性
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @author Jasmine
|
||||
* @since 2024/01/30 11:39
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "tlog")
|
||||
public class TLogProperties {
|
||||
/** 日志标签模板 */
|
||||
|
||||
/**
|
||||
* 日志标签模板
|
||||
*/
|
||||
private String pattern;
|
||||
/** 自动打印调用参数和时间 */
|
||||
|
||||
/**
|
||||
* 自动打印调用参数和时间
|
||||
*/
|
||||
private Boolean enableInvokeTimePrint;
|
||||
/** 自定义TraceId生成器 */
|
||||
|
||||
/**
|
||||
* 自定义 TraceId 生成器
|
||||
*/
|
||||
private String idGenerator;
|
||||
/** MDC模式 */
|
||||
|
||||
/**
|
||||
* MDC 模式
|
||||
*/
|
||||
private Boolean mdcEnable;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ package top.charles7c.continew.admin.common.config.tlog;
|
||||
|
||||
import com.yomahub.tlog.id.TLogIdGeneratorLoader;
|
||||
import com.yomahub.tlog.spring.TLogPropertyInit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
@ -26,19 +28,21 @@ import top.charles7c.continew.admin.common.config.properties.TLogProperties;
|
||||
/**
|
||||
* TLog 配置
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogConfiguration
|
||||
* @author Jasmine
|
||||
* @since 2024/01/30 11:39
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@EnableConfigurationProperties(TLogProperties.class)
|
||||
public class TLogConfiguration {
|
||||
|
||||
private final TLogProperties tLogProperties;
|
||||
|
||||
public TLogConfiguration(TLogProperties tLogProperties) {
|
||||
this.tLogProperties = tLogProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public TLogPropertyInit tLogPropertyInit() {
|
||||
@ -46,8 +50,7 @@ public class TLogConfiguration {
|
||||
tLogPropertyInit.setPattern(tLogProperties.getPattern());
|
||||
tLogPropertyInit.setEnableInvokeTimePrint(tLogProperties.getEnableInvokeTimePrint());
|
||||
tLogPropertyInit.setMdcEnable(tLogProperties.getMdcEnable());
|
||||
|
||||
// 设置自定义TraceId生成器
|
||||
// 设置自定义 TraceId 生成器
|
||||
TLogIdGeneratorLoader.setIdGenerator(new TraceIdGenerator());
|
||||
return tLogPropertyInit;
|
||||
}
|
||||
|
@ -28,26 +28,26 @@ import java.io.IOException;
|
||||
/**
|
||||
* TLog 过滤器
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogConfiguration
|
||||
* @author Jasmine
|
||||
* @since 2024/01/30 11:39
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Component
|
||||
public class TLogServletFilter implements Filter {
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request,
|
||||
ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
|
||||
if (request instanceof HttpServletRequest httpServletRequest && response instanceof HttpServletResponse httpServletResponse) {
|
||||
try {
|
||||
TLogWebCommon.loadInstance().preHandle((HttpServletRequest)request);
|
||||
// 把traceId放入response的header,为了方便有些人有这样的需求,从前端拿整条链路的traceId
|
||||
((HttpServletResponse)response).addHeader(TLogConstants.TLOG_TRACE_KEY, TLogContext.getTraceId());
|
||||
TLogWebCommon.loadInstance().preHandle(httpServletRequest);
|
||||
// 把 traceId 放入 response 的 header,为了方便有些人有这样的需求,从前端拿整条链路的 traceId
|
||||
httpServletResponse.addHeader(TLogConstants.TLOG_TRACE_KEY, TLogContext.getTraceId());
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
} finally {
|
||||
@ -56,9 +56,4 @@ public class TLogServletFilter implements Filter {
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,20 +20,20 @@ import com.yomahub.tlog.constant.TLogConstants;
|
||||
import com.yomahub.tlog.core.rpc.TLogLabelBean;
|
||||
import com.yomahub.tlog.core.rpc.TLogRPCHandler;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* TLog
|
||||
* TLog Web 通用拦截器
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogWebCommon
|
||||
* @author Jasmine
|
||||
* @since 2024/01/30 11:39
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
public class TLogWebCommon extends TLogRPCHandler {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(TLogWebCommon.class);
|
||||
|
||||
private static volatile TLogWebCommon tLogWebCommon;
|
||||
|
||||
public static TLogWebCommon loadInstance() {
|
||||
@ -53,9 +53,7 @@ public class TLogWebCommon extends TLogRPCHandler {
|
||||
String preIvkApp = request.getHeader(TLogConstants.PRE_IVK_APP_KEY);
|
||||
String preIvkHost = request.getHeader(TLogConstants.PRE_IVK_APP_HOST);
|
||||
String preIp = request.getHeader(TLogConstants.PRE_IP_KEY);
|
||||
|
||||
TLogLabelBean labelBean = new TLogLabelBean(preIvkApp, preIvkHost, preIp, traceId, spanId);
|
||||
|
||||
processProviderSide(labelBean);
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,15 @@ package top.charles7c.continew.admin.common.config.tlog;
|
||||
import com.yomahub.tlog.id.TLogIdGenerator;
|
||||
|
||||
/**
|
||||
* TLog 配置
|
||||
* TLog ID 自定义生成器
|
||||
*
|
||||
* @see TraceIdGenerator
|
||||
* @author Jasmine
|
||||
* @since 2024/01/30 11:39
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
public class TraceIdGenerator extends TLogIdGenerator {
|
||||
@Override
|
||||
public String generateTraceId() {
|
||||
String traceId = String.valueOf(System.nanoTime());
|
||||
return traceId;
|
||||
return String.valueOf(System.nanoTime());
|
||||
}
|
||||
}
|
@ -32,6 +32,8 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
import top.charles7c.continew.starter.extension.crud.annotation.EnableCrudRestController;
|
||||
import top.charles7c.continew.starter.web.annotation.EnableGlobalExceptionHandler;
|
||||
|
||||
@ -81,7 +83,8 @@ public class ContiNewAdminApplication implements ApplicationRunner {
|
||||
log.info("----------------------------------------------");
|
||||
log.info("{} service started successfully.", projectProperties.getName());
|
||||
log.info("API 地址:{}", baseUrl);
|
||||
if (SpringUtil.getProperty("springdoc.swagger-ui.enabled", boolean.class, false)) {
|
||||
String docEnabledProperty = PropertiesConstants.SPRINGDOC_SWAGGER_UI + StringConstants.DOT + PropertiesConstants.ENABLED;
|
||||
if (Boolean.TRUE.equals(SpringUtil.getProperty(docEnabledProperty, boolean.class, false))) {
|
||||
log.info("API 文档:{}/doc.html", baseUrl);
|
||||
}
|
||||
log.info("----------------------------------------------");
|
||||
|
@ -37,6 +37,11 @@ continew-starter.log:
|
||||
## 项目日志配置
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
## TLog 链路追踪配置
|
||||
tlog:
|
||||
enable-invoke-time-print: false
|
||||
pattern: '[$spanId][$traceId]'
|
||||
mdc-enable: false
|
||||
|
||||
--- ### 线程池配置
|
||||
continew-starter.thread-pool:
|
||||
@ -247,10 +252,4 @@ generator:
|
||||
packageName: service.impl
|
||||
Controller:
|
||||
templatePath: generator/Controller.ftl
|
||||
packageName: controller
|
||||
|
||||
--- ### TLog
|
||||
tlog:
|
||||
enable-invoke-time-print: true
|
||||
pattern: '[$spanId][$traceId]'
|
||||
mdc-enable: false
|
||||
packageName: controller
|
10
pom.xml
10
pom.xml
@ -33,8 +33,6 @@
|
||||
<properties>
|
||||
<!-- 项目版本号 -->
|
||||
<revision>2.4.0-SNAPSHOT</revision>
|
||||
<tlog.version>1.5.1</tlog.version>
|
||||
<sonar.version>3.9.1.2184</sonar.version>
|
||||
</properties>
|
||||
|
||||
<!-- 全局依赖版本管理 -->
|
||||
@ -74,13 +72,6 @@
|
||||
<artifactId>continew-admin-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!--轻量级的分布式日志标记追踪神器-->
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>tlog-web-spring-boot-starter</artifactId>
|
||||
<version>${tlog.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@ -188,7 +179,6 @@
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>${sonar.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>verify</phase>
|
||||
|
Loading…
Reference in New Issue
Block a user