From d36419170b10716455fb1eb21d11827bde7d408b Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 20 Mar 2023 13:01:49 +0100 Subject: [PATCH] also use -loglevel in localserve, and fail if the loglevel is invalid --- localserve.go | 7 +++++++ main.go | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/localserve.go b/localserve.go index a6d9635..33078d9 100644 --- a/localserve.go +++ b/localserve.go @@ -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)) } + 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. recvidbuf, err := os.ReadFile(filepath.Join(dir, "receivedid.key")) if err == nil && len(recvidbuf) != 16+8 { diff --git a/main.go b/main.go index 1108f77..62612d9 100644 --- a/main.go +++ b/main.go @@ -356,9 +356,11 @@ var pedantic bool // loglevels from the config file. func mustLoadConfig() { mox.MustLoadConfig(false) - if level, ok := mlog.Levels[loglevel]; ok && loglevel != "" { + 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)) } if pedantic { moxvar.Pedantic = true