diff --git a/core/logx/tracelogger_test.go b/core/logx/tracelogger_test.go index 466ee87c..956b393c 100644 --- a/core/logx/tracelogger_test.go +++ b/core/logx/tracelogger_test.go @@ -29,11 +29,11 @@ func TestTraceLog(t *testing.T) { func TestTraceError(t *testing.T) { var buf mockWriter + atomic.StoreUint32(&initialized, 1) + errorLog = newLogWriter(log.New(&buf, "", flags)) ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock) l := WithContext(ctx).(*traceLogger) SetLevel(InfoLevel) - atomic.StoreUint32(&initialized, 1) - errorLog = newLogWriter(log.New(&buf, "", flags)) l.WithDuration(time.Second).Error(testlog) assert.True(t, strings.Contains(buf.String(), mockTraceId)) assert.True(t, strings.Contains(buf.String(), mockSpanId)) @@ -45,11 +45,11 @@ func TestTraceError(t *testing.T) { func TestTraceInfo(t *testing.T) { var buf mockWriter + atomic.StoreUint32(&initialized, 1) + infoLog = newLogWriter(log.New(&buf, "", flags)) ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock) l := WithContext(ctx).(*traceLogger) SetLevel(InfoLevel) - atomic.StoreUint32(&initialized, 1) - infoLog = newLogWriter(log.New(&buf, "", flags)) l.WithDuration(time.Second).Info(testlog) assert.True(t, strings.Contains(buf.String(), mockTraceId)) assert.True(t, strings.Contains(buf.String(), mockSpanId)) @@ -61,11 +61,11 @@ func TestTraceInfo(t *testing.T) { func TestTraceSlow(t *testing.T) { var buf mockWriter + atomic.StoreUint32(&initialized, 1) + slowLog = newLogWriter(log.New(&buf, "", flags)) ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock) l := WithContext(ctx).(*traceLogger) SetLevel(InfoLevel) - atomic.StoreUint32(&initialized, 1) - slowLog = newLogWriter(log.New(&buf, "", flags)) l.WithDuration(time.Second).Slow(testlog) assert.True(t, strings.Contains(buf.String(), mockTraceId)) assert.True(t, strings.Contains(buf.String(), mockSpanId)) @@ -77,10 +77,10 @@ func TestTraceSlow(t *testing.T) { func TestTraceWithoutContext(t *testing.T) { var buf mockWriter - l := WithContext(context.Background()).(*traceLogger) - SetLevel(InfoLevel) atomic.StoreUint32(&initialized, 1) infoLog = newLogWriter(log.New(&buf, "", flags)) + l := WithContext(context.Background()).(*traceLogger) + SetLevel(InfoLevel) l.WithDuration(time.Second).Info(testlog) assert.False(t, strings.Contains(buf.String(), mockTraceId)) assert.False(t, strings.Contains(buf.String(), mockSpanId))