pkg/log/zap_intest.go

19 lines
459 B
Go
Raw Normal View History

2023-09-18 15:51:20 +08:00
package log
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func EnableZapInGoTest() {
encoderConfig := zap.NewDevelopmentEncoderConfig()
encoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
encoder := zapcore.NewConsoleEncoder(encoderConfig)
newCore := zapcore.NewCore(encoder, zapcore.Lock(os.Stdout), zapcore.DebugLevel)
// 替换 zap 的全局 Logger
zap.ReplaceGlobals(zap.New(zapcore.NewTee(zap.L().Core(), newCore)))
}