32 lines
569 B
Go
32 lines
569 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// LoggerConfig 日志配置
|
|
type LoggerConfig struct {
|
|
Level string `mapstructure:"level"` // debug, info, warn, error
|
|
File string `mapstructure:"file"` // 日志文件路径,为空则输出到控制台
|
|
}
|
|
|
|
// Validate 验证日志配置
|
|
func (c *LoggerConfig) Validate() error {
|
|
if c.Level == "" {
|
|
c.Level = "info"
|
|
}
|
|
|
|
validLevels := map[string]bool{
|
|
"debug": true,
|
|
"info": true,
|
|
"warn": true,
|
|
"error": true,
|
|
}
|
|
|
|
if !validLevels[c.Level] {
|
|
return fmt.Errorf("invalid log level: %s", c.Level)
|
|
}
|
|
|
|
return nil
|
|
}
|