MCPcopy
hub / github.com/redpanda-data/console / TestStructuredLogging

Function TestStructuredLogging

backend/pkg/logger/logger_test.go:211–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

209}
210
211func TestStructuredLogging(t *testing.T) {
212 var buf bytes.Buffer
213 logger := NewSlogLogger(
214 WithOutput(&buf),
215 WithFormat(FormatJSON), // Explicitly use JSON mode for predictable output
216 )
217
218 logger.Info("structured log",
219 slog.String("string", "value"),
220 slog.Int("int", 42),
221 slog.Float64("float", 3.14),
222 slog.Bool("bool", true),
223 slog.Any("nested", map[string]any{
224 "key": "value",
225 }),
226 )
227
228 // Parse the JSON output
229 var logEntry map[string]any
230 err := json.Unmarshal(buf.Bytes(), &logEntry)
231 require.NoError(t, err)
232
233 assert.Equal(t, "structured log", logEntry["msg"])
234 assert.Equal(t, "value", logEntry["string"])
235 assert.Equal(t, float64(42), logEntry["int"]) // JSON numbers are float64
236 assert.Equal(t, 3.14, logEntry["float"])
237 assert.Equal(t, true, logEntry["bool"])
238}
239
240func TestWithFormat(t *testing.T) {
241 tests := []struct {

Callers

nothing calls this directly

Calls 4

NewSlogLoggerFunction · 0.85
WithOutputFunction · 0.85
WithFormatFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…