diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/FilterOrderConst.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/FilterOrderConst.java index 184b1e02..24910615 100644 --- a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/FilterOrderConst.java +++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/FilterOrderConst.java @@ -9,9 +9,9 @@ package com.orion.ops.framework.common.constant; */ public interface FilterOrderConst { - int CORS_FILTER = Integer.MIN_VALUE; + int TRICE_ID_FILTER = Integer.MIN_VALUE + 1000; - int TRICE_ID_FILTER = Integer.MIN_VALUE + 10; + int CORS_FILTER = Integer.MIN_VALUE + 2000; int MYBATIS_CACHE_CLEAR_FILTER = Integer.MIN_VALUE + 100000; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/filter/TraceIdFilter.java b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/filter/TraceIdFilter.java index cdf5d0fa..fb72feff 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/filter/TraceIdFilter.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/filter/TraceIdFilter.java @@ -2,6 +2,7 @@ package com.orion.ops.framework.web.core.filter; import com.orion.lang.id.UUIds; import com.orion.ops.framework.common.meta.TraceIdHolder; +import org.slf4j.MDC; import org.springframework.web.filter.OncePerRequestFilter; import javax.servlet.FilterChain; @@ -21,19 +22,26 @@ public class TraceIdFilter extends OncePerRequestFilter { private static final String TRACE_ID_HEADER = "trace-id"; + private static final String TRACE_ID_MDC = "tid"; + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { try { // 获 traceId String traceId = UUIds.random32(); + // 设置应用上下文 TraceIdHolder.set(traceId); + // 设置日志上下文 + MDC.put(TRACE_ID_MDC, traceId); // 设置响应头 response.setHeader(TRACE_ID_HEADER, traceId); // 执行请求 filterChain.doFilter(request, response); } finally { - // 清理缓存 + // 清理应用上下文 TraceIdHolder.remove(); + // 清理日志上下文 + MDC.clear(); } } diff --git a/orion-ops-launch/src/main/resources/application.yaml b/orion-ops-launch/src/main/resources/application.yaml index 2dbf30ee..57912249 100644 --- a/orion-ops-launch/src/main/resources/application.yaml +++ b/orion-ops-launch/src/main/resources/application.yaml @@ -64,6 +64,9 @@ spring: type: REDIS redis: time-to-live: 1h + output: + ansi: + enabled: detect mybatis-plus: configuration: @@ -91,6 +94,21 @@ knife4j: setting: language: zh_cn +logging: + file: + path: ${user.home}/orion/logs/orion-ops-pro + name: ${logging.file.path}/app.log + logback: + rollingpolicy: + clean-history-on-start: false + file-name-pattern: ${logging.file.path}/rolling/orion-ops-rolling-%d{yyyy-MM-dd}.%i.gz + max-history: 30 + max-file-size: 16MB + total-size-cap: 0B + pattern: + console: '%clr(%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %boldBlue([%X{tid}]) %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}' + file: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} [%X{tid}] [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}" + orion: # 版本 version: @revision@