From 8f865df4d65851cfee4c99ca79fbc01b924e5609 Mon Sep 17 00:00:00 2001 From: qloog Date: Sat, 27 Jul 2024 15:07:28 +0800 Subject: [PATCH] chore: optimize log --- pkg/log/logger.go | 9 +-------- pkg/log/zap.go | 8 -------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/pkg/log/logger.go b/pkg/log/logger.go index e58d90f10..4803ea419 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -13,7 +13,6 @@ import ( // log is A global variable so that log functions can be directly accessed var log Logger -var logger Logger var zl *zap.Logger // Fields Type to pass when we want to call WithFields for structured logging @@ -58,7 +57,6 @@ func Init(opts ...Option) Logger { if err != nil { _ = fmt.Errorf("init newZapLogger err: %v", err) } - _ = zl // log 用于支持模块级的方法调用,所以要比其他 Logger 多跳一层 log, err = newLoggerWithCallerSkip(cfg, 1, opts...) @@ -66,17 +64,12 @@ func Init(opts ...Option) Logger { _ = fmt.Errorf("init newLogger err: %v", err) } - logger, err = newLogger(cfg, opts...) - if err != nil { - _ = fmt.Errorf("init logger err: %v", err) - } - return log } // GetLogger return a log func GetLogger() Logger { - return logger + return log } // GetZapLogger return raw zap logger diff --git a/pkg/log/zap.go b/pkg/log/zap.go index 6aab4de7f..c344596da 100644 --- a/pkg/log/zap.go +++ b/pkg/log/zap.go @@ -83,14 +83,6 @@ func newLoggerWithCallerSkip(cfg *Config, skip int, opts ...Option) (Logger, err return &zapLogger{sugarLogger: buildLogger(cfg, defaultSkip+skip).Sugar()}, nil } -// newLogger new logger -func newLogger(cfg *Config, opts ...Option) (Logger, error) { - for _, opt := range opts { - opt(cfg) - } - return newLoggerWithCallerSkip(cfg, 0) -} - func buildLogger(cfg *Config, skip int) *zap.Logger { logDir = cfg.LoggerDir if strings.HasSuffix(logDir, "/") {