From 8a3d2ba909b4ef9cb1d21866343c4fc960d0da63 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 24 Nov 2020 10:05:53 +0300 Subject: [PATCH] Remove unused components - remove graceful context - remove logger component Signed-off-by: Evgeniy Kulikov --- cmd/gate/app-graceful.go | 24 ------- cmd/gate/app-logger.go | 142 --------------------------------------- 2 files changed, 166 deletions(-) delete mode 100644 cmd/gate/app-graceful.go delete mode 100644 cmd/gate/app-logger.go diff --git a/cmd/gate/app-graceful.go b/cmd/gate/app-graceful.go deleted file mode 100644 index 8469d6289..000000000 --- a/cmd/gate/app-graceful.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "context" - "os" - "os/signal" - "syscall" - - "go.uber.org/zap" -) - -// newGracefulContext returns graceful context -func newGracefulContext(l *zap.Logger) context.Context { - ctx, cancel := context.WithCancel(context.Background()) - go func() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) - sig := <-ch - l.Info("received signal", - zap.String("signal", sig.String())) - cancel() - }() - return ctx -} diff --git a/cmd/gate/app-logger.go b/cmd/gate/app-logger.go deleted file mode 100644 index fe772c2d3..000000000 --- a/cmd/gate/app-logger.go +++ /dev/null @@ -1,142 +0,0 @@ -package main - -import ( - "strings" - - "github.com/spf13/viper" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc/grpclog" -) - -type ( - zapLogger struct { - zapcore.Core - log *zap.SugaredLogger - } - - logger interface { - grpclog.LoggerV2 - Println(v ...interface{}) - } -) - -const ( - formatJSON = "json" - formatConsole = "console" - - defaultSamplingInitial = 100 - defaultSamplingThereafter = 100 -) - -func gRPCLogger(l *zap.Logger) logger { - log := l.WithOptions( - // skip gRPCLog + zapLogger in caller - zap.AddCallerSkip(2)) - return &zapLogger{ - Core: log.Core(), - log: log.Sugar(), - } -} - -func safeLevel(lvl string) zap.AtomicLevel { - switch strings.ToLower(lvl) { - case "debug": - return zap.NewAtomicLevelAt(zap.DebugLevel) - case "warn": - return zap.NewAtomicLevelAt(zap.WarnLevel) - case "error": - return zap.NewAtomicLevelAt(zap.ErrorLevel) - case "fatal": - return zap.NewAtomicLevelAt(zap.FatalLevel) - case "panic": - return zap.NewAtomicLevelAt(zap.PanicLevel) - default: - return zap.NewAtomicLevelAt(zap.InfoLevel) - } -} - -func newLogger(v *viper.Viper) *zap.Logger { - c := zap.NewProductionConfig() - - c.OutputPaths = []string{"stdout"} - c.ErrorOutputPaths = []string{"stdout"} - - if v.IsSet("logger.sampling") { - c.Sampling = &zap.SamplingConfig{ - Initial: defaultSamplingInitial, - Thereafter: defaultSamplingThereafter, - } - - if val := v.GetInt(cfgLoggerSamplingInitial); val > 0 { - c.Sampling.Initial = val - } - - if val := v.GetInt(cfgLoggerSamplingThereafter); val > 0 { - c.Sampling.Thereafter = val - } - } - - // logger level - c.Level = safeLevel(v.GetString(cfgLoggerLevel)) - traceLvl := safeLevel(v.GetString(cfgLoggerTraceLevel)) - - // logger format - switch f := v.GetString(cfgLoggerFormat); strings.ToLower(f) { - case formatConsole: - c.Encoding = formatConsole - default: - c.Encoding = formatJSON - } - - // logger time - c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - - l, err := c.Build( - // enable trace only for current log-level - zap.AddStacktrace(traceLvl)) - if err != nil { - panic(err) - } - - if v.GetBool(cfgLoggerNoDisclaimer) { - return l - } - - name := v.GetString(cfgApplicationName) - version := v.GetString(cfgApplicationVersion) - - return l.With( - zap.String("app_name", name), - zap.String("app_version", version)) -} - -func (z *zapLogger) Info(args ...interface{}) { z.log.Info(args...) } - -func (z *zapLogger) Infoln(args ...interface{}) { z.log.Info(args...) } - -func (z *zapLogger) Infof(format string, args ...interface{}) { z.log.Infof(format, args...) } - -func (z *zapLogger) Println(args ...interface{}) { z.log.Info(args...) } - -func (z *zapLogger) Printf(format string, args ...interface{}) { z.log.Infof(format, args...) } - -func (z *zapLogger) Warning(args ...interface{}) { z.log.Warn(args...) } - -func (z *zapLogger) Warningln(args ...interface{}) { z.log.Warn(args...) } - -func (z *zapLogger) Warningf(format string, args ...interface{}) { z.log.Warnf(format, args...) } - -func (z *zapLogger) Error(args ...interface{}) { z.log.Error(args...) } - -func (z *zapLogger) Errorln(args ...interface{}) { z.log.Error(args...) } - -func (z *zapLogger) Errorf(format string, args ...interface{}) { z.log.Errorf(format, args...) } - -func (z *zapLogger) Fatal(args ...interface{}) { z.log.Fatal(args...) } - -func (z *zapLogger) Fatalln(args ...interface{}) { z.log.Fatal(args...) } - -func (z *zapLogger) Fatalf(format string, args ...interface{}) { z.Fatalf(format, args...) } - -func (z *zapLogger) V(int) bool { return z.Enabled(zapcore.DebugLevel) }