操作日志和访问日志

This commit is contained in:
2025-11-11 22:32:46 +08:00
parent efc079c0e5
commit 12a0ff8afc
17 changed files with 2300 additions and 4 deletions
+16
View File
@@ -207,6 +207,15 @@ func init() {
}
})
// 在请求完成后记录操作日志(包括访问/读取行为)
beego.InsertFilter("/api/*", beego.FinishRouter, func(ctx *context.Context) {
// 避免记录操作日志接口自身以免循环
if strings.HasPrefix(ctx.Input.URL(), "/api/operation-logs") {
return
}
middleware.OperationLogMiddleware(ctx)
})
// 添加主页路由
beego.Router("/", &controllers.MainController{})
@@ -329,4 +338,11 @@ func init() {
beego.Router("/api/program-infos/public", &controllers.ProgramInfoController{}, "get:GetProgramInfosPublic")
beego.Router("/api/files/public", &controllers.FileController{}, "get:GetFilesPublic")
// 操作日志路由
beego.Router("/api/operation-logs", &controllers.OperationLogController{}, "get:GetOperationLogs")
beego.Router("/api/operation-logs/:id", &controllers.OperationLogController{}, "get:GetOperationLogById")
beego.Router("/api/operation-logs/user/stats", &controllers.OperationLogController{}, "get:GetUserStats")
beego.Router("/api/operation-logs/tenant/stats", &controllers.OperationLogController{}, "get:GetTenantStats")
beego.Router("/api/operation-logs/clear", &controllers.OperationLogController{}, "post:ClearOldLogs")
}