-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattribsrecorder.go
160 lines (138 loc) · 4.61 KB
/
attribsrecorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package golog
// import (
// "fmt"
// "time"
// )
// var (
// _ Writer = new(attribsRecorder)
// _ fmt.Stringer = new(attribsRecorder)
// )
// // attribsRecorder implements the Writer interface
// // and records all logged attributes that can be retrieved
// // with the Attribs() method.
// type attribsRecorder struct {
// currentKey string
// writingSlice bool
// currentSlice Attrib
// recorded Attribs
// }
// // NewAttribsRecorder returns a Writer that records all logged attributes
// // instead of formatting and printing them somewhere.
// // The recorded values can be retrieved with the Attrs() method.
// func NewAttribsRecorder() *attribsRecorder { return new(attribsRecorder) }
// // Attribs returns the recorded values
// func (r *attribsRecorder) Attribs() Attribs {
// return r.recorded
// }
// func (r *attribsRecorder) BeginMessage(logger *Logger, t time.Time, level Level, text string) Writer {
// panic("BeginMessage not supported by golog.attribsRecorder")
// }
// func (r *attribsRecorder) CommitMessage() {
// panic("calling golog.Message.Log() after golog.Logger.With() is not valid, call golog.Message.SubLogger() instead")
// }
// func (r *attribsRecorder) FlushUnderlying() {}
// func (r *attribsRecorder) String() string {
// return fmt.Sprintf("golog.attribsRecorder with %d recored attribs", r.recorded)
// }
// func (r *attribsRecorder) WriteKey(key string) {
// r.currentKey = key
// }
// func (r *attribsRecorder) WriteSliceKey(key string) {
// r.currentKey = key
// r.writingSlice = true
// }
// func (r *attribsRecorder) WriteSliceEnd() {
// r.recorded = append(r.recorded, r.currentSlice)
// r.currentSlice = nil
// r.writingSlice = false
// }
// func (r *attribsRecorder) WriteNil() {
// r.recorded = append(r.recorded, Nil{r.currentKey})
// }
// func (r *attribsRecorder) WriteBool(val bool) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Bools); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Bools{r.currentKey, []bool{val}}
// }
// } else {
// r.recorded = append(r.recorded, Bool{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteInt(val int64) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Ints); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Ints{r.currentKey, []int64{val}}
// }
// } else {
// r.recorded = append(r.recorded, Int{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteUint(val uint64) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Uints); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Uints{r.currentKey, []uint64{val}}
// }
// } else {
// r.recorded = append(r.recorded, Uint{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteFloat(val float64) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Floats); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Floats{r.currentKey, []float64{val}}
// }
// } else {
// r.recorded = append(r.recorded, Float{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteString(val string) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Strings); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Strings{r.currentKey, []string{val}}
// }
// } else {
// r.recorded = append(r.recorded, String{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteError(val error) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*Errors); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &Errors{r.currentKey, []error{val}}
// }
// } else {
// r.recorded = append(r.recorded, Error{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteUUID(val [16]byte) {
// if r.writingSlice {
// // Need pointer type to be able to modify slice.Vals
// if slice, ok := r.currentSlice.(*UUIDs); ok {
// slice.Vals = append(slice.Vals, val)
// } else {
// r.currentSlice = &UUIDs{r.currentKey, [][16]byte{val}}
// }
// } else {
// r.recorded = append(r.recorded, UUID{r.currentKey, val})
// }
// }
// func (r *attribsRecorder) WriteJSON(val []byte) {
// r.recorded = append(r.recorded, JSON{r.currentKey, val})
// }