(t *testing.T)
| 209 | } |
| 210 | |
| 211 | func 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 | |
| 240 | func TestWithFormat(t *testing.T) { |
| 241 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…