Skip to content

Commit 0377302

Browse files
committed
Add operation record, and the user ID is not well thought out how to parse~
1 parent 80ffe7d commit 0377302

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

server/config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ log:
5858
stdout: 'DEBUG'
5959
file: 'DEBUG'
6060

61-
# operation configuration
61+
# operation record configuration
6262
operation:
63-
skip_paths:
63+
skip-paths:
6464
- '/base/login'
6565
- '/base/register'
66-
- '/sysOperationRecord/getSysOperationRecordList'
66+
- '/sysOperationRecord/getSysOperationRecordList'
67+
- '/sysOperationRecord/deleteSysOperationRecord'

server/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ type Sqlite struct {
7373
}
7474

7575
type Operation struct {
76-
SkipPaths []string `mapstructure: "skip_paths" json:"skip_paths" yaml: "username"`
76+
SkipPaths []string `mapstructure:"skip-paths" json:"skipPaths" yaml:"skip-paths"`
7777
}

server/middleware/operation.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package middleware
22

33
import (
44
"bytes"
5-
"fmt"
65
"gin-vue-admin/global"
76
"gin-vue-admin/model"
87
"gin-vue-admin/service"
@@ -35,10 +34,9 @@ func RecordRequestBody() gin.HandlerFunc {
3534
func OperationRecord() gin.HandlerFunc {
3635
return gin.LoggerWithConfig(gin.LoggerConfig{
3736
Formatter: func(param gin.LogFormatterParams) string {
38-
fmt.Println(global.GVA_CONFIG.Operation.SkipPaths)
37+
// 防止加载查询参数,再次过滤
3938
for _, v := range global.GVA_CONFIG.Operation.SkipPaths {
4039
if strings.Contains(param.Path, v) {
41-
fmt.Println(param.Path)
4240
return ""
4341
}
4442
}
@@ -49,15 +47,15 @@ func OperationRecord() gin.HandlerFunc {
4947
Status: param.StatusCode,
5048
Latency: param.Latency,
5149
Agent: param.Request.UserAgent(),
52-
ErrorMessage: string(body),
50+
ErrorMessage: param.ErrorMessage,
51+
Body: string(body),
5352
UserId: int(userId),
5453
})
5554
if err != nil {
5655
global.GVA_LOG.Error(err)
5756
}
5857
return ""
5958
},
60-
// 暂时没考虑好
6159
Output: nil,
6260
SkipPaths: global.GVA_CONFIG.Operation.SkipPaths,
6361
})

server/model/sys_operation_record.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ type SysOperationRecord struct {
1616
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:''"`
1717
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:''"`
1818
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:''"`
19+
Body string `json:"body" form:"body" gorm:"column:body;comment:'请求Body'"`
1920
UserId int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:''"`
2021
}

0 commit comments

Comments
 (0)