forked from rs/zerolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.go
126 lines (124 loc) · 2.98 KB
/
fields.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
package zerolog
import (
"sort"
"time"
)
func appendFields(dst []byte, fields map[string]interface{}) []byte {
keys := make([]string, 0, len(fields))
for key := range fields {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
dst = appendKey(dst, key)
switch val := fields[key].(type) {
case string:
dst = appendString(dst, val)
case []byte:
dst = appendBytes(dst, val)
case error:
dst = appendError(dst, val)
case []error:
dst = appendErrors(dst, val)
case bool:
dst = appendBool(dst, val)
case int:
dst = appendInt(dst, val)
case int8:
dst = appendInt8(dst, val)
case int16:
dst = appendInt16(dst, val)
case int32:
dst = appendInt32(dst, val)
case int64:
dst = appendInt64(dst, val)
case uint:
dst = appendUint(dst, val)
case uint8:
dst = appendUint8(dst, val)
case uint16:
dst = appendUint16(dst, val)
case uint32:
dst = appendUint32(dst, val)
case uint64:
dst = appendUint64(dst, val)
case float32:
dst = appendFloat32(dst, val)
case float64:
dst = appendFloat64(dst, val)
case time.Time:
dst = appendTime(dst, val, TimeFieldFormat)
case time.Duration:
dst = appendDuration(dst, val, DurationFieldUnit, DurationFieldInteger)
case *string:
dst = appendString(dst, *val)
case *bool:
dst = appendBool(dst, *val)
case *int:
dst = appendInt(dst, *val)
case *int8:
dst = appendInt8(dst, *val)
case *int16:
dst = appendInt16(dst, *val)
case *int32:
dst = appendInt32(dst, *val)
case *int64:
dst = appendInt64(dst, *val)
case *uint:
dst = appendUint(dst, *val)
case *uint8:
dst = appendUint8(dst, *val)
case *uint16:
dst = appendUint16(dst, *val)
case *uint32:
dst = appendUint32(dst, *val)
case *uint64:
dst = appendUint64(dst, *val)
case *float32:
dst = appendFloat32(dst, *val)
case *float64:
dst = appendFloat64(dst, *val)
case *time.Time:
dst = appendTime(dst, *val, TimeFieldFormat)
case *time.Duration:
dst = appendDuration(dst, *val, DurationFieldUnit, DurationFieldInteger)
case []string:
dst = appendStrings(dst, val)
case []bool:
dst = appendBools(dst, val)
case []int:
dst = appendInts(dst, val)
case []int8:
dst = appendInts8(dst, val)
case []int16:
dst = appendInts16(dst, val)
case []int32:
dst = appendInts32(dst, val)
case []int64:
dst = appendInts64(dst, val)
case []uint:
dst = appendUints(dst, val)
// case []uint8:
// dst = appendUints8(dst, val)
case []uint16:
dst = appendUints16(dst, val)
case []uint32:
dst = appendUints32(dst, val)
case []uint64:
dst = appendUints64(dst, val)
case []float32:
dst = appendFloats32(dst, val)
case []float64:
dst = appendFloats64(dst, val)
case []time.Time:
dst = appendTimes(dst, val, TimeFieldFormat)
case []time.Duration:
dst = appendDurations(dst, val, DurationFieldUnit, DurationFieldInteger)
case nil:
dst = appendNil(dst)
default:
dst = appendInterface(dst, val)
}
}
return dst
}