remove context key printing into logging content for context feature of package glog

This commit is contained in:
John Guo
2021-08-19 15:35:41 +08:00
parent 050c93ee8d
commit 314bee2b4e
3 changed files with 1 additions and 13 deletions

View File

@ -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 != "" {

View File

@ -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)
})

View File

@ -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)
})