also use -loglevel in localserve, and fail if the loglevel is invalid

This commit is contained in:
Mechiel Lukkien 2023-03-20 13:01:49 +01:00
parent 98b5a27fd2
commit d36419170b
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View file

@ -86,6 +86,13 @@ during those commands instead of during "data".
log.Fatalx("loading mox localserve config (hint: when creating a new config with -dir, the directory must not yet exist)", err, mlog.Field("dir", dir)) log.Fatalx("loading mox localserve config (hint: when creating a new config with -dir, the directory must not yet exist)", err, mlog.Field("dir", dir))
} }
if level, ok := mlog.Levels[loglevel]; loglevel != "" && ok {
mox.Conf.Log[""] = level
mlog.SetConfig(mox.Conf.Log)
} else if loglevel != "" && !ok {
log.Fatal("unknown loglevel", mlog.Field("loglevel", loglevel))
}
// Initialize receivedid. // Initialize receivedid.
recvidbuf, err := os.ReadFile(filepath.Join(dir, "receivedid.key")) recvidbuf, err := os.ReadFile(filepath.Join(dir, "receivedid.key"))
if err == nil && len(recvidbuf) != 16+8 { if err == nil && len(recvidbuf) != 16+8 {

View file

@ -356,9 +356,11 @@ var pedantic bool
// loglevels from the config file. // loglevels from the config file.
func mustLoadConfig() { func mustLoadConfig() {
mox.MustLoadConfig(false) mox.MustLoadConfig(false)
if level, ok := mlog.Levels[loglevel]; ok && loglevel != "" { if level, ok := mlog.Levels[loglevel]; loglevel != "" && ok {
mox.Conf.Log[""] = level mox.Conf.Log[""] = level
mlog.SetConfig(mox.Conf.Log) mlog.SetConfig(mox.Conf.Log)
} else if loglevel != "" && !ok {
log.Fatal("unknown loglevel", mlog.Field("loglevel", loglevel))
} }
if pedantic { if pedantic {
moxvar.Pedantic = true moxvar.Pedantic = true