增加日志系统
This commit is contained in:
@@ -15,6 +15,7 @@ type Config struct {
|
||||
JWTSecret string
|
||||
Storage StorageConfig
|
||||
SMS SMSConfig
|
||||
Log LogConfig
|
||||
}
|
||||
|
||||
type StorageConfig struct {
|
||||
@@ -33,6 +34,13 @@ type SMSConfig struct {
|
||||
AliyunLoginTemplateCode string
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Level string
|
||||
Dir string
|
||||
EnableConsole bool
|
||||
EnableFile bool
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
return Config{
|
||||
AppEnv: getEnv("APP_ENV", "development"),
|
||||
@@ -56,6 +64,12 @@ func Load() Config {
|
||||
AliyunSignName: getEnv("ALIYUN_SMS_SIGN_NAME", ""),
|
||||
AliyunLoginTemplateCode: getEnv("ALIYUN_SMS_LOGIN_TEMPLATE_CODE", ""),
|
||||
},
|
||||
Log: LogConfig{
|
||||
Level: getEnv("LOG_LEVEL", "info"),
|
||||
Dir: getEnv("LOG_DIR", "logs"),
|
||||
EnableConsole: getEnvBool("LOG_ENABLE_CONSOLE", true),
|
||||
EnableFile: getEnvBool("LOG_ENABLE_FILE", true),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,3 +92,15 @@ func getEnvInt(key string, fallback int) int {
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func getEnvBool(key string, fallback bool) bool {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return fallback
|
||||
}
|
||||
parsed, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user