Documentation
¶
Index ¶
- Variables
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func GetDailyLogFilename(baseFilename string) string
- func Info(msg string, fields ...zap.Field)
- func Init(cfg *LogConfig, mode string) (err error)
- func InitWithAlert(cfg *LogConfig, mode string, notifiers []NotificationService) (err error)
- func IsAlertEnabled() bool
- func LogAccess(method, path, clientIP string, statusCode int, latency int64)
- func LogConfigLoaded(configPath string)
- func LogDatabaseConnected(driver, dsn string)
- func LogError(msg string, fields ...zap.Field)
- func LogServerConfig(addr, dbDriver, dsn, mode, logLevel, logFilename string, ...)
- func LogStartupSuccess(addr string)
- func LogTaskStarted(taskName string)
- func Panic(msg string, fields ...zap.Field)
- func ResetAlertStats()
- func Sync()
- func Warn(msg string, fields ...zap.Field)
- type AlertConfig
- type AlertInfo
- type AlertManager
- type AlertStats
- type LogConfig
- type LogEntry
- type NotificationService
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Lg *zap.Logger
)
Functions ¶
func GetDailyLogFilename ¶
GetDailyLogFilename 获取按日期分割的日志文件名
func InitWithAlert ¶
func InitWithAlert(cfg *LogConfig, mode string, notifiers []NotificationService) (err error)
InitWithAlert 初始化logger和预警功能
func LogDatabaseConnected ¶
func LogDatabaseConnected(driver, dsn string)
LogDatabaseConnected 记录数据库连接成功日志
func LogServerConfig ¶
func LogServerConfig(addr, dbDriver, dsn, mode, logLevel, logFilename string, logMaxSize, logMaxAge, logMaxBackups int)
LogServerConfig 记录服务器配置日志
Types ¶
type AlertConfig ¶
type AlertConfig struct {
Enabled bool `mapstructure:"enabled"` // 是否启用预警
ErrorThreshold int `mapstructure:"error_threshold"` // 错误日志阈值
WarningThreshold int `mapstructure:"warning_threshold"` // 警告日志阈值
TimeWindow time.Duration `mapstructure:"time_window"` // 时间窗口
CooldownPeriod time.Duration `mapstructure:"cooldown_period"` // 冷却期
AdminEmails []string `mapstructure:"admin_emails"` // 管理员邮箱列表
AdminPhones []string `mapstructure:"admin_phones"` // 管理员手机号列表
AdminUserIDs []uint `mapstructure:"admin_user_ids"` // 管理员用户ID列表
NotificationTypes []string `mapstructure:"notification_types"` // 通知类型: email, sms, internal
}
AlertConfig 预警配置
type AlertInfo ¶
type AlertInfo struct {
Type string `json:"type"` // 预警类型: error, warning
Count int `json:"count"` // 日志数量
Threshold int `json:"threshold"` // 阈值
TimeWindow time.Duration `json:"time_window"` // 时间窗口
StartTime time.Time `json:"start_time"` // 开始时间
EndTime time.Time `json:"end_time"` // 结束时间
SampleLogs []LogEntry `json:"sample_logs"` // 示例日志
Metadata map[string]string `json:"metadata"` // 额外元数据
}
AlertInfo 预警信息
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager 预警管理器
func NewAlertManager ¶
func NewAlertManager(config *AlertConfig, notifiers ...NotificationService) *AlertManager
NewAlertManager 创建预警管理器
func (*AlertManager) CheckAndAlert ¶
CheckAndAlert 检查并发送预警
type AlertStats ¶
type AlertStats struct {
ErrorCount int `json:"error_count"`
WarningCount int `json:"warning_count"`
LastAlert time.Time `json:"last_alert"`
WindowStart time.Time `json:"window_start"`
}
AlertStats 预警统计
Click to show internal directories.
Click to hide internal directories.