Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Aug 28, 2024
1 parent efc8187 commit 2ea221c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
// global Logger and SugaredLogger.
var (
_globalMu sync.RWMutex
_globalL = zap.Must(zap.NewProduction(pkgCallerSkip))
_globalS = _globalL.Sugar()
_globalL *Logger
_globalS *SugaredLogger
)

func init() {
SetLogger(zap.Must(zap.NewProduction()))
}

func NewLeveled(l Level, options ...Option) (*Logger, error) {
switch l {
case SilentLevel:
Expand All @@ -31,12 +35,11 @@ func NewLeveled(l Level, options ...Option) (*Logger, error) {

// SetLogger sets the global Logger and SugaredLogger.
func SetLogger(logger *Logger) {
// apply pkgCallerSkip to global loggers.
logger = logger.WithOptions(pkgCallerSkip)
_globalMu.Lock()
_globalL = logger
_globalS = logger.Sugar()
_globalMu.Unlock()
defer _globalMu.Unlock()
// apply pkgCallerSkip to global loggers.
_globalL = logger.WithOptions(pkgCallerSkip)
_globalS = _globalL.Sugar()
}

func logf(lvl Level, template string, args ...any) {
Expand Down

0 comments on commit 2ea221c

Please sign in to comment.