package log import ( "testing" "github.com/go-kratos/kratos/v2/log" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func TestZapLogger(t *testing.T) { encoder := zapcore.EncoderConfig{ TimeKey: "t", LevelKey: "level", NameKey: "logger", CallerKey: "caller", MessageKey: "msg", StacktraceKey: "stack", EncodeTime: zapcore.ISO8601TimeEncoder, LineEnding: zapcore.DefaultLineEnding, EncodeLevel: zapcore.LowercaseLevelEncoder, EncodeDuration: zapcore.SecondsDurationEncoder, EncodeCaller: zapcore.FullCallerEncoder, } logger := NewZapLogger( encoder, zap.NewAtomicLevelAt(zapcore.DebugLevel), zap.AddStacktrace( zap.NewAtomicLevelAt(zapcore.ErrorLevel)), zap.AddCaller(), zap.AddCallerSkip(2), zap.Development(), ) zlog := log.NewHelper(logger) zlog.Infow("name", "kratos", "from", "opensource") zlog.Infow("name", "kratos", "from") defer logger.Sync() }