forked from go-kratos/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zap_test.go
40 lines (36 loc) · 1.01 KB
/
zap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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")
// zap stdout/stderr Sync bugs in OSX, see https://github.com/uber-go/zap/issues/370
_ = logger.Sync()
}