优化日志

This commit is contained in:
yml2213
2026-06-19 13:02:28 +08:00
parent 59b9dd12ef
commit 878daa4ab8
6 changed files with 419 additions and 8 deletions
+30
View File
@@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"strconv"
)
// defaultAppPaths 收集运行时路径,支持环境变量覆盖,方便不同平台和部署方式调整。
@@ -25,6 +26,35 @@ func envOrDefault(key, fallback string) string {
return fallback
}
// loadTraceConfig 读取 trace 开关;默认关闭,避免保存敏感调试数据。
func loadTraceConfig() TraceConfig {
return TraceConfig{
Enabled: isTruthyEnv("DOUYU_TRACE"),
MaxBodyBytes: envInt("DOUYU_TRACE_MAX_BODY", 0),
}
}
func isTruthyEnv(key string) bool {
switch os.Getenv(key) {
case "1", "true", "TRUE", "yes", "YES", "on", "ON":
return true
default:
return false
}
}
func envInt(key string, fallback int) int {
raw := os.Getenv(key)
if raw == "" {
return fallback
}
value, err := strconv.Atoi(raw)
if err != nil || value <= 0 {
return fallback
}
return value
}
// loadConfig 读取配置文件;缺失时安静使用内置默认配置。
func loadConfig(path string) Config {
cfg := Config{TimeAPIURL: defaultTimeAPI}