|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
@ -31,6 +32,7 @@ func TestTraceError(t *testing.T) {
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
|
|
|
|
atomic.StoreUint32(&initialized, 1)
|
|
|
|
errorLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
errorLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
l.WithDuration(time.Second).Error(testlog)
|
|
|
|
l.WithDuration(time.Second).Error(testlog)
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
@ -46,6 +48,7 @@ func TestTraceInfo(t *testing.T) {
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
|
|
|
|
atomic.StoreUint32(&initialized, 1)
|
|
|
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
l.WithDuration(time.Second).Info(testlog)
|
|
|
|
l.WithDuration(time.Second).Info(testlog)
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
@ -61,6 +64,7 @@ func TestTraceSlow(t *testing.T) {
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
ctx := context.WithValue(context.Background(), tracespec.TracingKey, mock)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
l := WithContext(ctx).(*traceLogger)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
|
|
|
|
atomic.StoreUint32(&initialized, 1)
|
|
|
|
slowLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
slowLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
l.WithDuration(time.Second).Slow(testlog)
|
|
|
|
l.WithDuration(time.Second).Slow(testlog)
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
|
assert.True(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
@ -75,6 +79,7 @@ func TestTraceWithoutContext(t *testing.T) {
|
|
|
|
var buf mockWriter
|
|
|
|
var buf mockWriter
|
|
|
|
l := WithContext(context.Background()).(*traceLogger)
|
|
|
|
l := WithContext(context.Background()).(*traceLogger)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
SetLevel(InfoLevel)
|
|
|
|
|
|
|
|
atomic.StoreUint32(&initialized, 1)
|
|
|
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
infoLog = newLogWriter(log.New(&buf, "", flags))
|
|
|
|
l.WithDuration(time.Second).Info(testlog)
|
|
|
|
l.WithDuration(time.Second).Info(testlog)
|
|
|
|
assert.False(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
|
assert.False(t, strings.Contains(buf.String(), mockTraceId))
|
|
|
|