From 59f2d740a163cf6c7a990788e52458964216183f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= Date: Wed, 31 Jul 2024 15:09:46 +0200 Subject: [PATCH] fix: logging setup --- cmd/waku/node.go | 11 +++++------ examples/chat2-reliable/main.go | 6 ++++-- waku/v2/utils/logger.go | 7 ++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cmd/waku/node.go b/cmd/waku/node.go index 695f08b08..ed3314ee8 100644 --- a/cmd/waku/node.go +++ b/cmd/waku/node.go @@ -86,7 +86,11 @@ func nonRecoverError(err error) error { func Execute(options NodeOptions) error { // Set encoding for logs (console, json, ...) // Note that libp2p reads the encoding from GOLOG_LOG_FMT env var. - utils.InitLogger(options.LogEncoding, options.LogOutput, "gowaku") + lvl, err := zapcore.ParseLevel(options.LogLevel) + if err != nil { + return err + } + utils.InitLogger(options.LogEncoding, options.LogOutput, "gowaku", lvl) hostAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", options.Address, options.Port)) if err != nil { @@ -124,11 +128,6 @@ func Execute(options NodeOptions) error { go metricsServer.Start() } - lvl, err := zapcore.ParseLevel(options.LogLevel) - if err != nil { - return err - } - nodeOpts := []node.WakuNodeOption{ node.WithLogger(logger), node.WithLogLevel(lvl), diff --git a/examples/chat2-reliable/main.go b/examples/chat2-reliable/main.go index 518578975..92c343fde 100644 --- a/examples/chat2-reliable/main.go +++ b/examples/chat2-reliable/main.go @@ -6,6 +6,7 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" "github.com/waku-org/go-waku/waku/v2/utils" + "go.uber.org/zap/zapcore" ) var options Options @@ -15,11 +16,12 @@ func main() { Flags: getFlags(), Action: func(c *cli.Context) error { - lvl, err := logging.LevelFromString(options.LogLevel) + lvl, err := zapcore.ParseLevel(options.LogLevel) if err != nil { return err } - logging.SetAllLoggers(lvl) + + logging.SetAllLoggers(logging.LogLevel(lvl)) utils.InitLogger("console", "file:chat2.log", "chat2", lvl) execute(options) diff --git a/waku/v2/utils/logger.go b/waku/v2/utils/logger.go index 304896b96..02b82eee4 100644 --- a/waku/v2/utils/logger.go +++ b/waku/v2/utils/logger.go @@ -6,6 +6,7 @@ import ( logging "github.com/ipfs/go-log/v2" "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) var log *zap.Logger @@ -19,7 +20,7 @@ func Logger(name ...string) *zap.Logger { } if log == nil { - InitLogger("console", "stdout", loggerName, logging.LevelInfo) + InitLogger("console", "stdout", loggerName, zapcore.InfoLevel) } return log } @@ -39,9 +40,9 @@ func MessagesLogger(prefix string) *zap.Logger { } // InitLogger initializes a global logger using an specific encoding -func InitLogger(encoding string, output string, name string, level logging.LogLevel) { +func InitLogger(encoding string, output string, name string, level zapcore.Level) { cfg := logging.GetConfig() - cfg.Level = level + cfg.Level = logging.LogLevel(level) if encoding == "json" { cfg.Format = logging.JSONOutput