/
logger_test.go
54 lines (45 loc) · 1.06 KB
/
logger_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package zapray
import (
"context"
"fmt"
"testing"
"github.com/aws/aws-xray-sdk-go/xray"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
)
func TestZaprayLogger(t *testing.T) {
core, recorded := observer.New(zapcore.InfoLevel)
log := zap.New(core)
ctx := context.Background()
segCtx, seg := xray.BeginSegment(ctx, "testseg")
defer seg.Close(nil)
zprl := NewLogger(log)
zprl.Trace(segCtx).Info("test log")
if len(recorded.All()) != 1 {
t.Errorf("expected 1 call got %d", len(recorded.All()))
}
containsTrace := ""
for _, f := range recorded.All()[0].Context {
if f.Key == "@xrayTraceId" {
containsTrace = f.String
}
}
fmt.Println("seg", seg.ID)
fmt.Println("seg", xray.TraceID(segCtx))
if containsTrace == "" {
t.Errorf("expected log to contain traceId")
}
}
var ctx context.Context
var zprl *Logger
func init() {
actx := context.Background()
ctx, _ = xray.BeginSegment(actx, "testseg")
zprl, _ = NewDevelopment()
}
func BenchMem(b *testing.B) {
for n := 0; n < b.N; n++ {
zprl.Trace(ctx).Info("test log")
}
}