Codebase list golang-github-inconshreveable-log15 / 03eda65
New upstream version 2.14 aviau 5 years ago
4 changed file(s) with 38 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
22 sudo: false
33
44 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
2323 Spencer Nelson <s@spenczar.com>
2424 Tomasz Grodzki <tg@users.noreply.github.com>
2525 Trevor Gattis <github@trevorgattis.com>
26 Varun Agrawal <vagrawal@pindropsecurity.com>
2627 Vincent Vanackere <vincent.vanackere@gmail.com>
2728 Will McGovern <will@brkt.com>
3838 // a terminal with color-coded level output and terser human friendly timestamp.
3939 // This format should only be used for interactive programs or while developing.
4040 //
41 // [TIME] [LEVEL] MESAGE key=value key=value ...
41 // [TIME] [LEVEL] MESSAGE key=value key=value ...
4242 //
4343 // Example:
4444 //
194194
195195 func formatJSONValue(value interface{}) interface{} {
196196 value = formatShared(value)
197
197198 switch value.(type) {
198199 case int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64, string:
200 return value
201 case interface{}, map[string]interface{}, []interface{}:
199202 return value
200203 default:
201204 return fmt.Sprintf("%+v", value)
112112 validate("x", float64(1)) // all numbers are floats in JSON land
113113 validate("y", 3.2)
114114 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"])
115143 }
116144
117145 type testtype struct {