mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-24 03:46:37 +02:00
48851a1ffd
* add examples/zap/log
40 lines
946 B
Go
40 lines
946 B
Go
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()
|
|
}
|