mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
remove context key printing into logging content for context feature of package glog
This commit is contained in:
@ -187,7 +187,7 @@ func (l *Logger) print(ctx context.Context, level int, values ...interface{}) {
|
||||
if ctxStr != "" {
|
||||
ctxStr += ", "
|
||||
}
|
||||
ctxStr += fmt.Sprintf("%s: %+v", ctxKey, ctxValue)
|
||||
ctxStr += gconv.String(ctxValue)
|
||||
}
|
||||
}
|
||||
if ctxStr != "" {
|
||||
|
||||
@ -25,9 +25,7 @@ func Test_Ctx(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "Span-Id", "abcdefg")
|
||||
|
||||
l.Ctx(ctx).Print(1, 2, 3)
|
||||
t.Assert(gstr.Count(w.String(), "Trace-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1234567890"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "Span-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "abcdefg"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1 2 3"), 1)
|
||||
})
|
||||
@ -46,9 +44,7 @@ func Test_Ctx_Config(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "Span-Id", "abcdefg")
|
||||
|
||||
l.Ctx(ctx).Print(1, 2, 3)
|
||||
t.Assert(gstr.Count(w.String(), "Trace-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1234567890"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "Span-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "abcdefg"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1 2 3"), 1)
|
||||
})
|
||||
|
||||
@ -33,16 +33,12 @@ func TestLogger_SetHandlers1(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "Span-Id", "abcdefg")
|
||||
|
||||
l.Ctx(ctx).Print(1, 2, 3)
|
||||
t.Assert(gstr.Count(w.String(), "Trace-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1234567890"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "Span-Id"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "abcdefg"), 1)
|
||||
t.Assert(gstr.Count(w.String(), "1 2 3"), 1)
|
||||
|
||||
t.Assert(arrayForHandlerTest1.Len(), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest1.At(0), "Trace-Id"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest1.At(0), "1234567890"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest1.At(0), "Span-Id"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest1.At(0), "abcdefg"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest1.At(0), "1 2 3"), 1)
|
||||
})
|
||||
@ -64,16 +60,12 @@ func TestLogger_SetHandlers2(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "Span-Id", "abcdefg")
|
||||
|
||||
l.Ctx(ctx).Print(1, 2, 3)
|
||||
t.Assert(gstr.Count(w.String(), "Trace-Id"), 0)
|
||||
t.Assert(gstr.Count(w.String(), "1234567890"), 0)
|
||||
t.Assert(gstr.Count(w.String(), "Span-Id"), 0)
|
||||
t.Assert(gstr.Count(w.String(), "abcdefg"), 0)
|
||||
t.Assert(gstr.Count(w.String(), "1 2 3"), 0)
|
||||
|
||||
t.Assert(arrayForHandlerTest2.Len(), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest2.At(0), "Trace-Id"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest2.At(0), "1234567890"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest2.At(0), "Span-Id"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest2.At(0), "abcdefg"), 1)
|
||||
t.Assert(gstr.Count(arrayForHandlerTest2.At(0), "1 2 3"), 1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user