[#49] Use zap.Logger in neofs-storage
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2fc2f8792e
commit
1a169a1a9d
2 changed files with 25 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue