From ab62f5add69cb18909e45d7780c6db1b9ac83624 Mon Sep 17 00:00:00 2001 From: aoiasd Date: Tue, 4 Jun 2024 15:45:48 +0800 Subject: [PATCH] support log level as dynamic config Signed-off-by: aoiasd --- cmd/roles/roles.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/roles/roles.go b/cmd/roles/roles.go index c0877ffc98ece..89832b50b325b 100644 --- a/cmd/roles/roles.go +++ b/cmd/roles/roles.go @@ -30,6 +30,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/zap" + "go.uber.org/zap/zapcore" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/cmd/components" @@ -249,6 +250,16 @@ func (mr *MilvusRoles) setupLogger() { } logutil.SetupLogger(&logConfig) + + params.Watch(params.LogCfg.Level.Key, config.NewHandler("log level handler", func(e *config.Event) { + level := zapcore.DebugLevel + if err := level.UnmarshalText([]byte(e.Value)); err != nil { + log.Warn("update log level failed", zap.String("level", e.Value), zap.Error(err)) + return + } + log.SetLevel(level) + log.Info("update log level", zap.String("level", e.Value)) + })) } // Register serves prometheus http service