Debian Codegraph @

mocktracer/mocklogrecord.go

raw
1 package mocktracer
2
3 import (
4 "fmt"
5 "reflect"
6 "time"
7
8 "github.com/opentracing/opentracing-go/log"
9 )
10
11 // MockLogRecord represents data logged to a Span via Span.LogFields or
12 // Span.LogKV.
13 type MockLogRecord struct {
14 Timestamp time.Time
15 Fields []MockKeyValue
16 }
17
18 // MockKeyValue represents a single key:value pair.
19 type MockKeyValue struct {
20 Key string
21
22 // All MockLogRecord values are coerced to strings via fmt.Sprint(), though
23 // we retain their type separately.
24 ValueKind reflect.Kind
25 ValueString string
26 }
27
28 // EmitString belongs to the log.Encoder interface
29 func (m *MockKeyValue) EmitString(key, value string) {
30 m.Key = key
31 m.ValueKind = reflect.TypeOf(value).Kind()
32 m.ValueString = fmt.Sprint(value)
33 }
34
35 // EmitBool belongs to the log.Encoder interface
36 func (m *MockKeyValue) EmitBool(key string, value bool) {
37 m.Key = key
38 m.ValueKind = reflect.TypeOf(value).Kind()
39 m.ValueString = fmt.Sprint(value)
40 }
41
42 // EmitInt belongs to the log.Encoder interface
43 func (m *MockKeyValue) EmitInt(key string, value int) {
44 m.Key = key
45 m.ValueKind = reflect.TypeOf(value).Kind()
46 m.ValueString = fmt.Sprint(value)
47 }
48
49 // EmitInt32 belongs to the log.Encoder interface
50 func (m *MockKeyValue) EmitInt32(key string, value int32) {
51 m.Key = key
52 m.ValueKind = reflect.TypeOf(value).Kind()
53 m.ValueString = fmt.Sprint(value)
54 }
55
56 // EmitInt64 belongs to the log.Encoder interface
57 func (m *MockKeyValue) EmitInt64(key string, value int64) {
58 m.Key = key
59 m.ValueKind = reflect.TypeOf(value).Kind()
60 m.ValueString = fmt.Sprint(value)
61 }
62
63 // EmitUint32 belongs to the log.Encoder interface
64 func (m *MockKeyValue) EmitUint32(key string, value uint32) {
65 m.Key = key
66 m.ValueKind = reflect.TypeOf(value).Kind()
67 m.ValueString = fmt.Sprint(value)
68 }
69
70 // EmitUint64 belongs to the log.Encoder interface
71 func (m *MockKeyValue) EmitUint64(key string, value uint64) {
72 m.Key = key
73 m.ValueKind = reflect.TypeOf(value).Kind()
74 m.ValueString = fmt.Sprint(value)
75 }
76
77 // EmitFloat32 belongs to the log.Encoder interface
78 func (m *MockKeyValue) EmitFloat32(key string, value float32) {
79 m.Key = key
80 m.ValueKind = reflect.TypeOf(value).Kind()
81 m.ValueString = fmt.Sprint(value)
82 }
83
84 // EmitFloat64 belongs to the log.Encoder interface
85 func (m *MockKeyValue) EmitFloat64(key string, value float64) {
86 m.Key = key
87 m.ValueKind = reflect.TypeOf(value).Kind()
88 m.ValueString = fmt.Sprint(value)
89 }
90
91 // EmitObject belongs to the log.Encoder interface
92 func (m *MockKeyValue) EmitObject(key string, value interface{}) {
93 m.Key = key
94 m.ValueKind = reflect.TypeOf(value).Kind()
95 m.ValueString = fmt.Sprint(value)
96 }
97
98 // EmitLazyLogger belongs to the log.Encoder interface
99 func (m *MockKeyValue) EmitLazyLogger(value log.LazyLogger) {
100 var meta MockKeyValue
101 value(&meta)
102 m.Key = meta.Key
103 m.ValueKind = meta.ValueKind
104 m.ValueString = meta.ValueString
105 }