MCPcopy Create free account
hub / github.com/zalando/skipper / TestApplicationLogJSONEnabled

Function TestApplicationLogJSONEnabled

logging/log_test.go:47–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestApplicationLogJSONEnabled(t *testing.T) {
48 var buf bytes.Buffer
49 _ = NewAccessLogger(Options{ApplicationLogOutput: &buf, ApplicationLogJSONEnabled: true})
50 msg := "Hello, world!"
51 log.Info(msg)
52
53 parsed := make(map[string]interface{})
54 err := json.Unmarshal(buf.Bytes(), &parsed)
55 if err != nil {
56 t.Errorf("failed to parse json log: %v", err)
57 }
58
59 if got := parsed["level"]; got != "info" {
60 t.Errorf("invalid level, expected: info, got: %v", got)
61 }
62
63 if got := parsed["msg"]; got != msg {
64 t.Errorf("invalid msg, expected: %s, got: %v", msg, got)
65 }
66
67 if got, ok := parsed["time"]; ok {
68 _, err := time.Parse(time.RFC3339, got.(string))
69 if err != nil {
70 t.Errorf("failed to parse time: %v", err)
71 }
72 } else {
73 t.Error("time is missing")
74 }
75
76 if len(parsed) != 3 {
77 t.Errorf("unexpected field count")
78 }
79}
80
81func TestApplicationLogJSONWithCustomFormatter(t *testing.T) {
82 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 6

NewAccessLoggerFunction · 0.85
BytesMethod · 0.80
InfoMethod · 0.65
ErrorfMethod · 0.65
ParseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…