优化日志系统

This commit is contained in:
yml2213
2026-06-19 12:10:55 +08:00
parent 1805edc63a
commit 59b9dd12ef
11 changed files with 232 additions and 66 deletions
+4 -5
View File
@@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"errors"
"log"
"os"
"path/filepath"
)
@@ -36,21 +35,21 @@ func loadConfig(path string) Config {
f, err := os.Open(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Printf("配置加载完成: 内置默认配置")
logEvent("配置", "info", "配置加载完成: 内置默认配置")
} else {
log.Printf("读取 %s 出错,使用内置默认配置: %v", path, err)
logEvent("配置", "warn", "读取 %s 出错,使用内置默认配置: %v", path, err)
}
return cfg
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&cfg); err != nil {
log.Printf("解析 %s 失败,使用内置默认配置: %v", path, err)
logEvent("配置", "warn", "解析 %s 失败,使用内置默认配置: %v", path, err)
return Config{TimeAPIURL: defaultTimeAPI}
}
if cfg.TimeAPIURL == "" {
cfg.TimeAPIURL = defaultTimeAPI
}
log.Printf("配置加载完成: %s", path)
logEvent("配置", "success", "配置加载完成: %s", path)
return cfg
}