1Panel/backend/app/api/v1/logs.go

121 lines
3.2 KiB
Go
Raw Normal View History

2022-08-16 15:30:23 +00:00
package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
2022-08-16 15:30:23 +00:00
"github.com/gin-gonic/gin"
)
2023-01-04 14:31:51 +00:00
// @Tags Logs
// @Summary Page login logs
// @Description 获取系统登录日志列表分页
// @Accept json
2023-02-07 10:48:32 +00:00
// @Param request body dto.SearchLgLogWithPage true "request"
2023-01-04 14:31:51 +00:00
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /logs/login [post]
2022-11-15 09:20:57 +00:00
func (b *BaseApi) GetLoginLogs(c *gin.Context) {
2023-02-07 10:48:32 +00:00
var req dto.SearchLgLogWithPage
2023-10-27 06:19:26 +00:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-08-16 15:30:23 +00:00
return
}
2022-11-15 09:20:57 +00:00
total, list, err := logService.PageLoginLog(req)
2022-08-16 15:30:23 +00:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}
2023-01-04 14:31:51 +00:00
// @Tags Logs
// @Summary Page operation logs
// @Description 获取系统操作日志列表分页
// @Accept json
2023-02-07 10:48:32 +00:00
// @Param request body dto.SearchOpLogWithPage true "request"
2023-01-04 14:31:51 +00:00
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /logs/operation [post]
2022-11-15 09:20:57 +00:00
func (b *BaseApi) GetOperationLogs(c *gin.Context) {
2023-02-07 10:48:32 +00:00
var req dto.SearchOpLogWithPage
2023-10-27 06:19:26 +00:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-08-16 15:30:23 +00:00
return
}
2022-11-15 09:20:57 +00:00
total, list, err := logService.PageOperationLog(req)
if err != nil {
2022-08-16 15:30:23 +00:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
2022-11-15 09:20:57 +00:00
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
2022-08-16 15:30:23 +00:00
}
2022-11-15 10:44:50 +00:00
2023-01-04 14:31:51 +00:00
// @Tags Logs
// @Summary Clean operation logs
// @Description 清空操作日志
// @Accept json
// @Param request body dto.CleanLog true "request"
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /logs/clean [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["logType"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空 [logType] 日志信息","formatEN":"Clean the [logType] log information"}
2022-11-15 10:44:50 +00:00
func (b *BaseApi) CleanLogs(c *gin.Context) {
2023-01-04 14:31:51 +00:00
var req dto.CleanLog
2023-10-27 06:19:26 +00:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-11-15 10:44:50 +00:00
return
}
2023-01-04 14:31:51 +00:00
if err := logService.CleanLogs(req.LogType); err != nil {
2022-11-15 10:44:50 +00:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
// @Tags Logs
// @Summary Load system log files
// @Description 获取系统日志文件列表
// @Success 200
// @Security ApiKeyAuth
// @Router /logs/system/files [get]
func (b *BaseApi) GetSystemFiles(c *gin.Context) {
data, err := logService.ListSystemLogFile()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, data)
}
// @Tags Logs
// @Summary Load system logs
// @Description 获取系统日志
// @Success 200
// @Security ApiKeyAuth
// @Router /logs/system [post]
func (b *BaseApi) GetSystemLogs(c *gin.Context) {
var req dto.OperationWithName
2023-10-27 06:19:26 +00:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
2023-10-27 06:19:26 +00:00
data, err := logService.LoadSystemLog(req.Name)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, data)
}