mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-26 17:01:37 +08:00
style: 优化部分代码及注释格式
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user