feat: 新增系统日志记录、查看与自动清理,VO 转换改用 MapStruct
- 新增访问/登录日志表与拦截器,登录成功/失败均记录,接口访问同时输出到应用日志 - 新增 /api/log/* 查询与 SSE 实时推送,运行日志默认最近 1 小时并支持日期/级别/关键字筛选 - 新增日志定时清理,保留天数可配置(默认 30 天,0 为永久保留) - 前端新增系统日志页(独立 URL 子路径、标签偏好记忆),入口位于顶部用户下拉菜单 - 实体到视图对象的属性拷贝改用 MapStruct 编译期生成
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
// 系统日志相关 API 接口:访问日志、登录日志与后端运行日志
|
||||
import request from './request'
|
||||
|
||||
/** HTTP 访问日志 */
|
||||
export interface HttpLog {
|
||||
id: number
|
||||
userId: number | null
|
||||
method: string | null
|
||||
path: string | null
|
||||
queryString: string | null
|
||||
status: number | null
|
||||
durationMs: number | null
|
||||
ip: string | null
|
||||
userAgent: string | null
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
/** 登录日志 */
|
||||
export interface LoginLog {
|
||||
id: number
|
||||
userId: number | null
|
||||
username: string | null
|
||||
success: boolean
|
||||
message: string | null
|
||||
ip: string | null
|
||||
userAgent: string | null
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
/** 分页结果 */
|
||||
export interface LogPageResult<T> {
|
||||
records: T[]
|
||||
total: number
|
||||
page: number
|
||||
size: number
|
||||
}
|
||||
|
||||
/** 应用运行日志 */
|
||||
export interface AppLog {
|
||||
file: string
|
||||
total: number
|
||||
lines: string[]
|
||||
}
|
||||
|
||||
/** 分页查询 HTTP 访问日志 */
|
||||
export function pageHttpLogs(params: {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
method?: string
|
||||
status?: number
|
||||
}) {
|
||||
return request.get('/log/http', { params })
|
||||
}
|
||||
|
||||
/** 分页查询登录日志 */
|
||||
export function pageLoginLogs(params: {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
success?: boolean
|
||||
}) {
|
||||
return request.get('/log/login', { params })
|
||||
}
|
||||
|
||||
/** 读取后端运行日志 */
|
||||
export function getAppLog(params: {
|
||||
date?: string
|
||||
level?: string
|
||||
keyword?: string
|
||||
lines: number
|
||||
since?: number
|
||||
}) {
|
||||
return request.get('/log/app', { params })
|
||||
}
|
||||
|
||||
/** 获取日志保留天数(0 表示永久保留) */
|
||||
export function getLogRetention() {
|
||||
return request.get('/app/log-retention')
|
||||
}
|
||||
|
||||
/** 更新日志保留天数(0 表示永久保留) */
|
||||
export function updateLogRetention(days: number) {
|
||||
return request.put('/app/log-retention', { days })
|
||||
}
|
||||
Reference in New Issue
Block a user