From 1a169a1a9dae5f9425595da0702943f3d65e1ab5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 25 Sep 2020 15:34:17 +0300 Subject: [PATCH] [#49] Use zap.Logger in neofs-storage Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 21 +++++++++++++++++++++ cmd/neofs-node/main.go | 6 ++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index b290e018e..1ab9f28b5 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -13,11 +13,20 @@ import ( "github.com/nspcc-dev/neofs-node/misc" "github.com/nspcc-dev/neofs-node/pkg/morph/client" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/spf13/viper" + "go.uber.org/zap" "google.golang.org/grpc" ) const ( + // logger keys + cfgLogLevel = "logger.level" + cfgLogFormat = "logger.format" + cfgLogTrace = "logger.trace_level" + cfgLogInitSampling = "logger.sampling.initial" + cfgLogThereafterSampling = "logger.sampling.thereafter" + // config keys for cfgNodeInfo cfgNodeKey = "node.key" cfgBootstrapAddress = "node.address" @@ -47,6 +56,8 @@ type cfg struct { viper *viper.Viper + log *zap.Logger + wg *sync.WaitGroup key *ecdsa.PrivateKey @@ -125,9 +136,13 @@ func initCfg(path string) *cfg { viperCfg.GetString(cfgContainerContract)) fatalOnErr(err) + log, err := logger.NewLogger(viperCfg) + fatalOnErr(err) + return &cfg{ ctx: context.Background(), viper: viperCfg, + log: log, wg: new(sync.WaitGroup), key: key, cfgAccounting: cfgAccounting{ @@ -186,4 +201,10 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgNetmapContract, "75194459637323ea8837d2afe8225ec74a5658c3") v.SetDefault(cfgNetmapFee, "1") + + v.SetDefault(cfgLogLevel, "info") + v.SetDefault(cfgLogFormat, "console") + v.SetDefault(cfgLogTrace, "fatal") + v.SetDefault(cfgLogInitSampling, 1000) + v.SetDefault(cfgLogThereafterSampling, 1000) } diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 74c8877ad..0cea0b023 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "fmt" "log" "github.com/nspcc-dev/neofs-node/pkg/util/grace" @@ -46,12 +45,15 @@ func bootUp(c *cfg) { } func wait(c *cfg) { + c.log.Info("application started") + <-c.ctx.Done() } func shutdown(c *cfg) { c.cfgGRPC.server.GracefulStop() - fmt.Println("gRPC server stopped") + + c.log.Info("gRPC server stopped") c.wg.Wait() }