pkg/log/zap_intest.go
2023-09-18 15:51:20 +08:00

19 lines
459 B
Go

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)))
}