Skip to content

Commit

Permalink
fix: logging setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vpavlin committed Jul 31, 2024
1 parent 07bee14 commit 59f2d74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
11 changes: 5 additions & 6 deletions cmd/waku/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 4 additions & 2 deletions examples/chat2-reliable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions waku/v2/utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 59f2d74

Please sign in to comment.