更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -25,7 +25,6 @@ func BeginOperationLog(ctx *context.Context) {
|
||||
if shouldSkipLogging(method, url) {
|
||||
return
|
||||
}
|
||||
fmt.Printf("[oplog-begin] method=%s url=%s\n", method, url)
|
||||
|
||||
// 解析用户信息(直接从 header 解析,不依赖 JWT 中间件设置的 context)
|
||||
var uid uint64
|
||||
@@ -43,6 +42,12 @@ func BeginOperationLog(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 匿名读请求不算操作:官网页面浏览和公开接口每次访问都落库,
|
||||
// 审计表会被 uid=0/module=unknown/action=查询 的流水淹掉。写操作仍照常记录。
|
||||
if method == "GET" && uid == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 采集请求信息
|
||||
reqBody := ""
|
||||
if rb := ctx.Input.RequestBody; len(rb) > 0 {
|
||||
@@ -72,11 +77,8 @@ func BeginOperationLog(ctx *context.Context) {
|
||||
Status: 1,
|
||||
ExecutionTime: 0,
|
||||
}
|
||||
_, err := models.Orm.Insert(logRow)
|
||||
if err != nil {
|
||||
if _, err := models.Orm.Insert(logRow); err != nil {
|
||||
fmt.Printf("[oplog] INSERT ERROR: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("[oplog] INSERTED uid=%d module=%s action=%s\n", uid, module, action)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user