config: allow setting log level from yaml config

This commit is contained in:
Muhammed Efe Cetin
2025-08-20 10:40:02 +03:00
committed by M. Efe Çetin
parent 5361f07b9e
commit cad1a5062c

View File

@@ -56,6 +56,11 @@ type Config struct {
// Special extensions for the download map
SpecialExtensions map[string]string `mapstructure:"specialExtensions"`
// LogLevel is the log level to use for the application.
// It can be one of: "debug", "info", "warn", "error", "fatal", "panic".
// If not set, it defaults to "warn".
LogLevel string `mapstructure:"logLevel"`
// ReloadFunc is called when a reload is done via http api.
ReloadFunc func()
@@ -112,6 +117,15 @@ func (r *Redirector) ReloadConfig() error {
}
}
// set log level
level, err := log.ParseLevel(r.config.LogLevel)
if err != nil {
log.WithField("level", r.config.LogLevel).Warning("Invalid log level, using default")
level = log.WarnLevel
}
log.SetLevel(level)
// db can be hot-reloaded if the file changed
r.db, err = maxminddb.Open(r.config.GeoDBPath)
if err != nil {