You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
946 B
39 lines
946 B
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()
|
|
}
|
|
|