Skip to content

Commit

Permalink
chore: optimize log
Browse files Browse the repository at this point in the history
  • Loading branch information
qloog committed Jul 27, 2024
1 parent 3575914 commit 8f865df
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
9 changes: 1 addition & 8 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,25 +57,19 @@ func Init(opts ...Option) Logger {
if err != nil {
_ = fmt.Errorf("init newZapLogger err: %v", err)
}
_ = zl

// log 用于支持模块级的方法调用,所以要比其他 Logger 多跳一层
log, err = newLoggerWithCallerSkip(cfg, 1, opts...)
if err != nil {
_ = 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
Expand Down
8 changes: 0 additions & 8 deletions pkg/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/") {
Expand Down

0 comments on commit 8f865df

Please sign in to comment.