Explorar o código

测试环境配置

dengsixing %!s(int64=3) %!d(string=hai) anos
pai
achega
232bcb4e18

+ 5 - 1
src/main/java/com/fdkankan/gateway/filter/AccessLogFilter.java

@@ -3,9 +3,11 @@ package com.fdkankan.gateway.filter;
 import cn.hutool.core.net.URLDecoder;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.fdkankan.common.constant.LoginType;
 import com.fdkankan.common.response.ResultData;
 import com.fdkankan.gateway.log.GatewayLog;
 import com.fdkankan.gateway.util.WebUtil;
+import com.yomahub.tlog.context.TLogContext;
 import lombok.extern.slf4j.Slf4j;
 import org.reactivestreams.Publisher;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -80,6 +82,8 @@ public class AccessLogFilter  implements GlobalFilter, Ordered {
         gatewayLog.setTargetServer(route.getId());
         gatewayLog.setRequestTime(new Date());
         gatewayLog.setIp(ipAddress);
+        gatewayLog.setTraceId(TLogContext.getTraceId());
+
 
         MediaType mediaType = request.getHeaders().getContentType();
 
@@ -160,7 +164,7 @@ public class AccessLogFilter  implements GlobalFilter, Ordered {
      * @param gatewayLog 网关日志
      */
     private void writeAccessLog(GatewayLog gatewayLog) {
-        log.info(gatewayLog.toString());
+        log.info(JSON.toJSONString(gatewayLog));
         //日志写入mongodb
         mongoTemplate.insert(gatewayLog, "gatewayLog");
     }

+ 5 - 0
src/main/java/com/fdkankan/gateway/log/GatewayLog.java

@@ -49,5 +49,10 @@ public class GatewayLog {
     /**执行时间*/
     @Field("executeTime")
     private long executeTime;
+    /**
+     * tlog日志id
+     */
+    @Field("traceId")
+    private String traceId;
 
 }

+ 2 - 2
src/main/resources/bootstrap-test.yml

@@ -4,7 +4,7 @@ spring:
   cloud:
     nacos:
       config:
-        server-addr: 192.168.0.47:8848
+        server-addr: 172.18.156.39:8848
         file-extension: yaml
         namespace: 4dkankan-test
         extension-configs:
@@ -20,7 +20,7 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
       discovery:
-        server-addr: 192.168.0.47:8848
+        server-addr: 172.18.156.39:8848
         namespace: 4dkankan-test
 
 management: