Skip to content

Commit cad1a50

Browse files
committed
config: allow setting log level from yaml config
1 parent 5361f07 commit cad1a50

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ type Config struct {
5656
// Special extensions for the download map
5757
SpecialExtensions map[string]string `mapstructure:"specialExtensions"`
5858

59+
// LogLevel is the log level to use for the application.
60+
// It can be one of: "debug", "info", "warn", "error", "fatal", "panic".
61+
// If not set, it defaults to "warn".
62+
LogLevel string `mapstructure:"logLevel"`
63+
5964
// ReloadFunc is called when a reload is done via http api.
6065
ReloadFunc func()
6166

@@ -112,6 +117,15 @@ func (r *Redirector) ReloadConfig() error {
112117
}
113118
}
114119

120+
// set log level
121+
level, err := log.ParseLevel(r.config.LogLevel)
122+
if err != nil {
123+
log.WithField("level", r.config.LogLevel).Warning("Invalid log level, using default")
124+
level = log.WarnLevel
125+
}
126+
127+
log.SetLevel(level)
128+
115129
// db can be hot-reloaded if the file changed
116130
r.db, err = maxminddb.Open(r.config.GeoDBPath)
117131
if err != nil {

0 commit comments

Comments
 (0)