feat: add configurable loglevel

This commit is contained in:
2026-04-22 22:29:58 +02:00
parent d6df67b643
commit f796ea229f
7 changed files with 38 additions and 17 deletions
+22 -5
View File
@@ -6,15 +6,19 @@ import (
"path/filepath"
"slices"
"strconv"
"strings"
)
type Environment struct {
Version string
Codename string
Version string
Codename string
LogLevel string
DataDirectory string
ContentDirectory string
Hostname string
Port int
WatchdogEnabled bool
WatchdogInterval int
WatchdogSyncMode string
@@ -33,7 +37,6 @@ func safeStringGrab(key, fallback string) string {
if v, ok := os.LookupEnv(key); ok {
return v
}
slog.Debug("using fallback", "key", key, "fallback", fallback)
return fallback
}
@@ -43,7 +46,6 @@ func safeIntGrab(key string, fallback int) int {
return i
}
}
slog.Debug("using fallback", "key", key, "fallback", fallback)
return fallback
}
@@ -62,7 +64,6 @@ func safeSyncModeGrab(key, fallback string) string {
return v
}
}
slog.Debug("using fallback", "key", key, "fallback", fallback)
return fallback
}
@@ -79,6 +80,7 @@ func GrabEnvironment() Environment {
// Basic server configuration
Version: safeStringGrab("VERSION", "0.0.1"),
Codename: safeStringGrab("CODENAME", "Magical Anomaly"),
LogLevel: safeStringGrab("LOG_LEVEL", "info"),
// GIN API configuration
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
@@ -96,3 +98,18 @@ func GrabEnvironment() Environment {
WatchdogSyncMode: safeStringGrab("WATCHDOG_SYNC_MODE", "strict"),
}
}
func ParseSlogLevel(s string) slog.Level {
switch strings.ToLower(s) {
case "debug":
return slog.LevelDebug
case "warn", "warning":
return slog.LevelWarn
case "error":
return slog.LevelError
case "info":
fallthrough
default:
return slog.LevelInfo
}
}