From de77d7838e730f0037976715a5122b38c91f4870 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 24 Nov 2020 10:06:39 +0300 Subject: [PATCH] Add logger constructor and replace graceful context Signed-off-by: Evgeniy Kulikov --- cmd/gate/main.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/cmd/gate/main.go b/cmd/gate/main.go index e49f090..ab0b183 100644 --- a/cmd/gate/main.go +++ b/cmd/gate/main.go @@ -1,10 +1,47 @@ package main +import ( + "github.com/nspcc-dev/cdn-neofs-sdk/grace" + "github.com/nspcc-dev/cdn-neofs-sdk/logger" + "github.com/spf13/viper" + "go.uber.org/zap" +) + +func newLogger(v *viper.Viper) *zap.Logger { + options := []logger.Option{ + logger.WithLevel(v.GetString("logger.level")), + logger.WithTraceLevel(v.GetString("logger.trace_level")), + + logger.WithFormat(v.GetString("logger.format")), + + logger.WithSamplingInitial(v.GetInt("logger.sampling.initial")), + logger.WithSamplingThereafter(v.GetInt("logger.sampling.thereafter")), + + logger.WithAppName(v.GetString("app_name")), + logger.WithAppVersion(v.GetString("app_version")), + } + + if v.GetBool("logger.no_caller") { + options = append(options, logger.WithoutCaller()) + } + + if v.GetBool("logger.no_disclaimer") { + options = append(options, logger.WithoutDisclaimer()) + } + + l, err := logger.New(options...) + if err != nil { + panic(err) + } + + return l +} + func main() { var ( v = newSettings() l = newLogger(v) - g = newGracefulContext(l) + g = grace.Context(l) a = newApp(g, l, v) )