Skip to content

Commit

Permalink
Update applogger.go
Browse files Browse the repository at this point in the history
  • Loading branch information
eynzhang committed Sep 29, 2020
1 parent 0705717 commit cc7e268
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion logging/applogger/applogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

var sugaredLogger *zap.SugaredLogger
var atomicLevel zap.AtomicLevel

func init() {
encoderCfg := zapcore.EncoderConfig {
Expand All @@ -17,10 +18,18 @@ func init() {
EncodeTime: zapcore.ISO8601TimeEncoder,
}

core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), os.Stdout, zap.DebugLevel)
// define default level as debug level
atomicLevel = zap.NewAtomicLevel()
atomicLevel.SetLevel(zapcore.DebugLevel)

core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), os.Stdout, atomicLevel)
sugaredLogger = zap.New(core).Sugar()
}

func SetLevel(level zapcore.Level) {
atomicLevel.SetLevel(level)
}

func Fatal(template string, args ...interface{}) {
sugaredLogger.Fatalf(template, args...)
}
Expand Down

0 comments on commit cc7e268

Please sign in to comment.