Browse Source

Add operation record, and the user ID is not well thought out how to parse~

granty1 4 years ago
parent
commit
037730278e

+ 4 - 3
server/config.yaml

@@ -58,9 +58,10 @@ log:
     stdout: 'DEBUG'
     file: 'DEBUG'
 
-# operation configuration
+# operation record configuration
 operation:
-    skip_paths:
+    skip-paths:
         - '/base/login'
         - '/base/register'
-        - '/sysOperationRecord/getSysOperationRecordList'
+        - '/sysOperationRecord/getSysOperationRecordList'
+        - '/sysOperationRecord/deleteSysOperationRecord'

+ 1 - 1
server/config/config.go

@@ -73,5 +73,5 @@ type Sqlite struct {
 }
 
 type Operation struct {
-	SkipPaths []string `mapstructure: "skip_paths" json:"skip_paths" yaml: "username"`
+	SkipPaths []string `mapstructure:"skip-paths" json:"skipPaths" yaml:"skip-paths"`
 }

+ 3 - 5
server/middleware/operation.go

@@ -2,7 +2,6 @@ package middleware
 
 import (
 	"bytes"
-	"fmt"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
 	"gin-vue-admin/service"
@@ -35,10 +34,9 @@ func RecordRequestBody() gin.HandlerFunc {
 func OperationRecord() gin.HandlerFunc {
 	return gin.LoggerWithConfig(gin.LoggerConfig{
 		Formatter: func(param gin.LogFormatterParams) string {
-			fmt.Println(global.GVA_CONFIG.Operation.SkipPaths)
+			// 防止加载查询参数,再次过滤
 			for _, v := range global.GVA_CONFIG.Operation.SkipPaths {
 				if strings.Contains(param.Path, v) {
-					fmt.Println(param.Path)
 					return ""
 				}
 			}
@@ -49,7 +47,8 @@ func OperationRecord() gin.HandlerFunc {
 				Status:       param.StatusCode,
 				Latency:      param.Latency,
 				Agent:        param.Request.UserAgent(),
-				ErrorMessage: string(body),
+				ErrorMessage: param.ErrorMessage,
+				Body:         string(body),
 				UserId:       int(userId),
 			})
 			if err != nil {
@@ -57,7 +56,6 @@ func OperationRecord() gin.HandlerFunc {
 			}
 			return ""
 		},
-		// 暂时没考虑好
 		Output:    nil,
 		SkipPaths: global.GVA_CONFIG.Operation.SkipPaths,
 	})

+ 1 - 0
server/model/sys_operation_record.go

@@ -16,5 +16,6 @@ type SysOperationRecord struct {
 	Latency      time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:''"`
 	Agent        string        `json:"agent" form:"agent" gorm:"column:agent;comment:''"`
 	ErrorMessage string        `json:"error_message" form:"error_message" gorm:"column:error_message;comment:''"`
+	Body         string        `json:"body" form:"body" gorm:"column:body;comment:'请求Body'"`
 	UserId       int           `json:"user_id" form:"user_id" gorm:"column:user_id;comment:''"`
 }