From 215b9202eaf3b54c0b859a3762a974a065de0a54 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Mon, 27 Feb 2023 19:33:51 +0800 Subject: [PATCH] feat: allow to change log level by reloading --- cmd/run.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/run.go b/cmd/run.go index 008f4d1..3178eb8 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -95,6 +95,7 @@ loop: switch sig { case nil: if reloading { + // Serve. reloading = false log.Warnln("[Reload] Serve") readyChan := make(chan bool, 1) @@ -108,6 +109,7 @@ loop: sdnotify.Ready() log.Warnln("[Reload] Finished") } else { + // Listening error. break loop } case syscall.SIGUSR1: @@ -115,6 +117,7 @@ loop: log.Warnln("[Reload] Received reload signal; prepare to reload") sdnotify.Reloading() + // Load new config. log.Warnln("[Reload] Load new config") conf, includes, err := readConfig(cfgFile) if err != nil { @@ -125,7 +128,11 @@ loop: continue } log.Infof("Include config files: [%v]", strings.Join(includes, ", ")) + // New logger. + log = logger.NewLogger(conf.Global.LogLevel, disableTimestamp) + logrus.SetLevel(log.Level) + // New control plane. obj := c.EjectBpf() log.Warnln("[Reload] Load new control plane") newC, err := newControlPlane(log, obj, conf)