19 lines
459 B
Go
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)))
|
||
|
}
|