MCPcopy
hub / github.com/rs/zerolog / TestSlogHandler_WithAttrs

Function TestSlogHandler_WithAttrs

slog_test.go:181–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func TestSlogHandler_WithAttrs(t *testing.T) {
182 var buf bytes.Buffer
183 zl := zerolog.New(&buf)
184 handler := zerolog.NewSlogHandler(zl)
185
186 child := handler.WithAttrs([]slog.Attr{
187 slog.String("component", "auth"),
188 slog.Int("version", 2),
189 })
190 logger := slog.New(child)
191
192 logger.Info("request handled")
193
194 m := decodeJSON(t, &buf)
195 if m["component"] != "auth" {
196 t.Errorf("expected component=auth, got %v", m["component"])
197 }
198 if m["version"] != float64(2) {
199 t.Errorf("expected version=2, got %v", m["version"])
200 }
201 if m["message"] != "request handled" {
202 t.Errorf("expected message 'request handled', got %v", m["message"])
203 }
204}
205
206func TestSlogHandler_WithAttrsEmpty(t *testing.T) {
207 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 7

WithAttrsMethod · 0.95
NewFunction · 0.92
NewSlogHandlerFunction · 0.92
decodeJSONFunction · 0.85
InfoMethod · 0.65
StringMethod · 0.45
IntMethod · 0.45

Tested by

no test coverage detected