From 314bee2b4e348e901761f491d80b883fd1701428 Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 19 Aug 2021 15:35:41 +0800 Subject: [PATCH] remove context key printing into logging content for context feature of package glog --- os/glog/glog_logger.go | 2 +- os/glog/glog_z_unit_ctx_test.go | 4 ---- os/glog/glog_z_unit_handler_test.go | 8 -------- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/os/glog/glog_logger.go b/os/glog/glog_logger.go index 5c6ea42e7..33dca1bf9 100644 --- a/os/glog/glog_logger.go +++ b/os/glog/glog_logger.go @@ -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 != "" { diff --git a/os/glog/glog_z_unit_ctx_test.go b/os/glog/glog_z_unit_ctx_test.go index dd1f80932..e56fe59fe 100644 --- a/os/glog/glog_z_unit_ctx_test.go +++ b/os/glog/glog_z_unit_ctx_test.go @@ -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) }) diff --git a/os/glog/glog_z_unit_handler_test.go b/os/glog/glog_z_unit_handler_test.go index 921beb9b5..31f922f13 100644 --- a/os/glog/glog_z_unit_handler_test.go +++ b/os/glog/glog_z_unit_handler_test.go @@ -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) })