mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 00:57:13 +08:00 
			
		
		
		
	feat: 系统日志新增 traceId 链路号记录,方便查看完整日志链路
This commit is contained in:
		| @@ -16,12 +16,12 @@ | ||||
|  | ||||
| package top.charles7c.continew.admin.common.config.tlog; | ||||
|  | ||||
| import com.yomahub.tlog.constant.TLogConstants; | ||||
| import com.yomahub.tlog.context.TLogContext; | ||||
| import jakarta.servlet.*; | ||||
| import jakarta.servlet.http.HttpServletRequest; | ||||
| import jakarta.servlet.http.HttpServletResponse; | ||||
| import org.springframework.stereotype.Component; | ||||
| import top.charles7c.continew.admin.common.constant.SysConstants; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| @@ -47,7 +47,7 @@ public class TLogServletFilter implements Filter { | ||||
|             try { | ||||
|                 TLogWebCommon.loadInstance().preHandle(httpServletRequest); | ||||
|                 // 把 traceId 放入 response 的 header,为了方便有些人有这样的需求,从前端拿整条链路的 traceId | ||||
|                 httpServletResponse.addHeader(TLogConstants.TLOG_TRACE_KEY, TLogContext.getTraceId()); | ||||
|                 httpServletResponse.addHeader(SysConstants.TRACE_ID, TLogContext.getTraceId()); | ||||
|                 chain.doFilter(request, response); | ||||
|                 return; | ||||
|             } finally { | ||||
|   | ||||
| @@ -17,6 +17,7 @@ | ||||
| package top.charles7c.continew.admin.common.config.tlog; | ||||
|  | ||||
| import com.yomahub.tlog.id.TLogIdGenerator; | ||||
| import com.yomahub.tlog.id.snowflake.UniqueIdGenerator; | ||||
|  | ||||
| /** | ||||
|  * TLog ID 自定义生成器 | ||||
| @@ -28,6 +29,6 @@ import com.yomahub.tlog.id.TLogIdGenerator; | ||||
| public class TraceIdGenerator extends TLogIdGenerator { | ||||
|     @Override | ||||
|     public String generateTraceId() { | ||||
|         return String.valueOf(System.nanoTime()); | ||||
|         return String.valueOf(UniqueIdGenerator.generateId()); | ||||
|     } | ||||
| } | ||||
| @@ -68,4 +68,9 @@ public class SysConstants { | ||||
|      * 描述类字段后缀 | ||||
|      */ | ||||
|     public static final String DESCRIPTION_FIELD_SUFFIX = "String"; | ||||
|  | ||||
|     /** | ||||
|      * Trace ID | ||||
|      */ | ||||
|     public static final String TRACE_ID = "traceId"; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user