New upstream version 2.14
aviau
5 years ago
2 | 2 |
sudo: false
|
3 | 3 |
|
4 | 4 |
go:
|
5 | |
- 1.3
|
6 | |
- 1.4
|
7 | |
- 1.5
|
8 | |
- 1.6
|
9 | |
- 1.7
|
10 | |
- 1.8
|
11 | |
- 1.9
|
12 | |
- tip
|
|
5 |
- 1.7.x
|
|
6 |
- 1.8.x
|
|
7 |
- 1.9.x
|
|
8 |
- 1.10.x
|
|
9 |
- master
|
23 | 23 |
Spencer Nelson <s@spenczar.com>
|
24 | 24 |
Tomasz Grodzki <tg@users.noreply.github.com>
|
25 | 25 |
Trevor Gattis <github@trevorgattis.com>
|
|
26 |
Varun Agrawal <vagrawal@pindropsecurity.com>
|
26 | 27 |
Vincent Vanackere <vincent.vanackere@gmail.com>
|
27 | 28 |
Will McGovern <will@brkt.com>
|
38 | 38 |
// a terminal with color-coded level output and terser human friendly timestamp.
|
39 | 39 |
// This format should only be used for interactive programs or while developing.
|
40 | 40 |
//
|
41 | |
// [TIME] [LEVEL] MESAGE key=value key=value ...
|
|
41 |
// [TIME] [LEVEL] MESSAGE key=value key=value ...
|
42 | 42 |
//
|
43 | 43 |
// Example:
|
44 | 44 |
//
|
|
194 | 194 |
|
195 | 195 |
func formatJSONValue(value interface{}) interface{} {
|
196 | 196 |
value = formatShared(value)
|
|
197 |
|
197 | 198 |
switch value.(type) {
|
198 | 199 |
case int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64, string:
|
|
200 |
return value
|
|
201 |
case interface{}, map[string]interface{}, []interface{}:
|
199 | 202 |
return value
|
200 | 203 |
default:
|
201 | 204 |
return fmt.Sprintf("%+v", value)
|
112 | 112 |
validate("x", float64(1)) // all numbers are floats in JSON land
|
113 | 113 |
validate("y", 3.2)
|
114 | 114 |
validate("lvl", "eror")
|
|
115 |
}
|
|
116 |
|
|
117 |
func TestJSONMap(t *testing.T) {
|
|
118 |
m := map[string]interface{}{
|
|
119 |
"name": "gopher",
|
|
120 |
"age": float64(5),
|
|
121 |
"language": "go",
|
|
122 |
}
|
|
123 |
|
|
124 |
l, buf := testFormatter(JsonFormat())
|
|
125 |
l.Error("logging structs", "struct", m)
|
|
126 |
|
|
127 |
var v map[string]interface{}
|
|
128 |
decoder := json.NewDecoder(buf)
|
|
129 |
if err := decoder.Decode(&v); err != nil {
|
|
130 |
t.Fatalf("Error decoding JSON: %v", v)
|
|
131 |
}
|
|
132 |
|
|
133 |
checkMap := func(key string, expected interface{}) {
|
|
134 |
if m[key] != expected {
|
|
135 |
t.Fatalf("Got %v expected %v for %v", m[key], expected, key)
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
mv := v["struct"].(map[string]interface{})
|
|
140 |
checkMap("name", mv["name"])
|
|
141 |
checkMap("age", mv["age"])
|
|
142 |
checkMap("language", mv["language"])
|
115 | 143 |
}
|
116 | 144 |
|
117 | 145 |
type testtype struct {
|