我有一个从自定义配置(即config.Build()
)生成的 Zap 记录器。我想通过调用来测试记录器,例如,logger.Info()
在测试方法中并断言结果以查看它是否符合配置集。我怎样才能做到这一点?
代码示例:
func GetLogger() *zap.Logger{
config := &zap.Config{
Encoding: "json",
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stdout"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "@m",
LevelKey: "@l",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "@t",
EncodeTime: zapcore.EpochMillisTimeEncoder,
CallerKey: "@c",
EncodeCaller: zapcore.ShortCallerEncoder,
StacktraceKey: "@x",
},
}
return config.Build()
}