-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.zzzgo
134 lines (118 loc) · 4.15 KB
/
line.zzzgo
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
package xop
import (
"fmt"
"github.com/xoplog/xop-go/xopat"
"github.com/xoplog/xop-go/xopbase"
"github.com/mohae/deepcopy"
)
type Key = xopat.K
// AnyWithoutRedaction
// The return value must be consumed for the line to be logged.
func (line *Line) AnyWithoutRedaction(k xopat.K, v interface{}) *Line {
line.line.Any(k, xopbase.ModelArg{Model: v})
return line
}
// Any can be used to log something that might be modified after this call. If any base
// logger does not immediately serialize, then the object will be copied using
// https://github.com/mohae/deepcopy 's Copy().
// The return value must be consumed for the line to be logged.
func (line *Line) Any(k xopat.K, v interface{}) *Line {
if line.skip {
return line
}
if line.logger.settings.redactAny != nil {
line.logger.settings.redactAny(line.line, k, v, !line.logger.span.referencesKept)
return line
}
if line.logger.span.referencesKept {
// TODO: make copy function configurable
v = deepcopy.Copy(v)
}
return line.AnyWithoutRedaction(k, v)
}
// Float32 adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) Float32(k xopat.K, v float32) *Line {
line.line.Float64(k, float64(v), xopbase.Float32DataType)
return line
}
// EmbeddedEnum adds a key/value pair to the current log line.
// The type of the value implies the key.
// The return value must be consumed for the line to be logged.
func (line *Line) EmbeddedEnum(k xopat.EmbeddedEnum) *Line {
return line.Enum(k.EnumAttribute(), k)
}
// Enum adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) Enum(k *xopat.EnumAttribute, v xopat.Enum) *Line {
line.line.Enum(k, v)
return line
}
// Error adds a key/value pair to the current log line.
// The default logging of an error is simply err.Error() to change
// that, set a redaction function.
// The return value must be consumed for the line to be logged.
func (line *Line) Error(k xopat.K, v error) *Line {
if line.skip {
return line
}
if line.logger.settings.redactError != nil {
line.logger.settings.redactError(line.line, k, v)
return line
}
line.line.String(k, v.Error(), xopbase.ErrorDataType)
return line
}
// Stringer adds a key/value pair to the current log line.
// The string can be redacted if a redaction function has been set.
// The return value must be consumed for the line to be logged.
func (line *Line) Stringer(k xopat.K, v fmt.Stringer) *Line {
if line.skip {
return line
}
if line.logger.settings.redactString != nil {
line.logger.settings.redactString(line.line, k, v.String())
return line
}
line.line.String(k, v.String(), xopbase.StringerDataType)
return line
}
// String adds a key/value pair to the current log line.
// The string can be redacted if a redaction function has been set.
// The return value must be consumed for the line to be logged.
func (line *Line) String(k xopat.K, v string) *Line {
if line.skip {
return line
}
if line.logger.settings.redactString != nil {
line.logger.settings.redactString(line.line, k, v)
return line
}
line.line.String(k, v, xopbase.StringDataType)
return line
}
// MACRO BaseDataWithoutType SKIP:Any
// ZZZ adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) ZZZ(k xopat.K, v zzz) *Line { line.line.ZZZ(k, v); return line }
// MACRO BaseDataWithType SKIP:String
// ZZZ adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) ZZZ(k xopat.K, v zzz) *Line {
line.line.ZZZ(k, v, xopbase.ZZZDataType)
return line
}
// MACRO Ints SKIP:Int64
// ZZZ adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) ZZZ(k xopat.K, v zzz) *Line {
line.line.Int64(k, int64(v), xopbase.ZZZDataType)
return line
}
// MACRO Uints SKIP:Uint64
// ZZZ adds a key/value pair to the current log line.
// The return value must be consumed for the line to be logged.
func (line *Line) ZZZ(k xopat.K, v zzz) *Line {
line.line.Uint64(k, uint64(v), xopbase.ZZZDataType)
return line
}