feat: 添加日志管理和敏感词过滤功能

- 新增日志管理模块:操作日志、登录日志、数据变更日志
- 新增敏感词过滤器 (sanitizer)
- 新增日志异步写入管理器
- 新增日志定时清理服务
- 优化帖子相关服务和上传服务
This commit is contained in:
2026-03-15 02:25:10 +08:00
parent d3065b30cc
commit ebd9cb8b04
31 changed files with 2753 additions and 60 deletions

View File

@@ -9,9 +9,45 @@ type ServerConfig struct {
// LogConfig 日志配置
type LogConfig struct {
Level string `mapstructure:"level"`
Encoding string `mapstructure:"encoding"`
OutputPaths []string `mapstructure:"output_paths"`
Level string `mapstructure:"level"`
Encoding string `mapstructure:"encoding"`
OutputPaths []string `mapstructure:"output_paths"`
Retention LogRetentionConfig `mapstructure:"retention"`
Async AsyncLogConfig `mapstructure:"async"`
Sensitive SensitiveLogConfig `mapstructure:"sensitive"`
Rotation LogRotationConfig `mapstructure:"rotation"`
}
// LogRetentionConfig 日志保留配置
type LogRetentionConfig struct {
AccessLog int `mapstructure:"access_log"` // HTTP访问日志(天)
OperationLog int `mapstructure:"operation_log"` // 操作日志(天)
LoginLog int `mapstructure:"login_log"` // 登录日志(天)
DataChange int `mapstructure:"data_change"` // 数据变更日志(天)
}
// AsyncLogConfig 异步日志配置
type AsyncLogConfig struct {
BufferSize int `mapstructure:"buffer_size"` // 通道缓冲大小
BatchSize int `mapstructure:"batch_size"` // 批量写入大小
FlushInterval string `mapstructure:"flush_interval"` // 刷新间隔
WorkerCount int `mapstructure:"worker_count"` // worker数量
EnableFallback bool `mapstructure:"enable_fallback"` // 启用降级
FallbackPath string `mapstructure:"fallback_path"` // 降级文件路径
}
// SensitiveLogConfig 敏感日志配置
type SensitiveLogConfig struct {
Enabled bool `mapstructure:"enabled"` // 启用脱敏
MaskFields []string `mapstructure:"mask_fields"` // 需脱敏字段
}
// LogRotationConfig 日志轮转配置
type LogRotationConfig struct {
MaxSize int `mapstructure:"max_size"` // 单个文件最大大小(MB)
MaxAge int `mapstructure:"max_age"` // 最大保留天数
MaxBackups int `mapstructure:"max_backups"` // 最大备份数
Compress bool `mapstructure:"compress"` // 压缩
}
// RateLimitConfig 限流配置