提交 03773027 编写于 作者: G granty1

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

上级 80ffe7d4
......@@ -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'
\ No newline at end of file
- '/sysOperationRecord/getSysOperationRecordList'
- '/sysOperationRecord/deleteSysOperationRecord'
\ No newline at end of file
......@@ -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"`
}
......@@ -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,
})
......
......@@ -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:''"`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册