MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestLogHandler_WithGroup

Function TestLogHandler_WithGroup

lambdacontext/logger_test.go:229–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestLogHandler_WithGroup(t *testing.T) {
230 var buf bytes.Buffer
231
232 opts := &slog.HandlerOptions{
233 Level: slog.LevelInfo,
234 ReplaceAttr: ReplaceAttr,
235 }
236 baseHandler := slog.NewJSONHandler(&buf, opts)
237 handler := &lambdaHandler{handler: baseHandler}
238
239 lc := &LambdaContext{AwsRequestID: "test-request"}
240 ctx := NewContext(context.Background(), lc)
241
242 logger := slog.New(handler).WithGroup("app").With("version", "1.0")
243 logger.InfoContext(ctx, "test message")
244
245 var logOutput map[string]interface{}
246 err := json.Unmarshal(buf.Bytes(), &logOutput)
247 require.NoError(t, err)
248
249 app, ok := logOutput["app"].(map[string]interface{})
250 require.True(t, ok, "expected 'app' group in output: %s", buf.String())
251 assert.Equal(t, "1.0", app["version"])
252 assert.Equal(t, "test-request", app["requestId"])
253}
254
255func TestLogHandler_WithFields(t *testing.T) {
256 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 3

WithGroupMethod · 0.80
NewContextFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…