优化日志
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user