Browse Source

特定接口日志过滤

xyxie 2 months ago
parent
commit
7258801121
1 changed files with 11 additions and 2 deletions
  1. 11 2
      controllers/base_auth.go

+ 11 - 2
controllers/base_auth.go

@@ -19,6 +19,10 @@ var AfterHandlerUrlMap = map[string][]AfterHandle{
 	"/edbapi/wind/refresh": {models.DeleteChartInfoDataRedis}, //指标刷新接口
 }
 
+var FilterLogsUrlMap = map[string]struct{}{
+	"/edbapi/calculate/base": {}, //指标计算接口
+}
+
 func init() {
 	/*if utils.RunMode == "release" {
 		logDir := `/data/rdlucklog/` + utils.APP_NAME_EN
@@ -142,8 +146,13 @@ func (c *BaseAuthController) JSON(data interface{}, hasIndent bool, coding bool)
 	if authorization == "" {
 		authorization = c.Ctx.Input.Header("Authorization")
 	}
-
-	utils.ApiLog.Info("uri:%s, authorization:%s, requestBody:%s, responseBody:%s, ip:%s", c.Ctx.Input.URI(), authorization, requestBody, content, ip)
+	urlPath := c.Ctx.Input.URI()
+	//是否需要过滤日志中的请求入参和返回值
+	if _, ok := FilterLogsUrlMap[urlPath]; ok {
+		utils.ApiLog.Info("uri:%s, authorization:%s, ip:%s", urlPath, authorization, ip)
+	} else {
+		utils.ApiLog.Info("uri:%s, authorization:%s, requestBody:%s, responseBody:%s, ip:%s", urlPath, authorization, requestBody, content, ip)
+	}
 	if coding {
 		content = []byte(utils.StringsToJSON(string(content)))
 	}