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

Function TestLogHandler_JSONFormat

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

Source from the content-addressed store, hash-verified

89}
90
91func TestLogHandler_JSONFormat(t *testing.T) {
92 var buf bytes.Buffer
93
94 opts := &slog.HandlerOptions{
95 Level: slog.LevelInfo,
96 ReplaceAttr: ReplaceAttr,
97 }
98 baseHandler := slog.NewJSONHandler(&buf, opts)
99 handler := &lambdaHandler{handler: baseHandler}
100
101 lc := &LambdaContext{AwsRequestID: "test-request-123"}
102 ctx := NewContext(context.Background(), lc)
103
104 logger := slog.New(handler)
105 logger.InfoContext(ctx, "test message", "key", "value")
106
107 var logOutput map[string]interface{}
108 err := json.Unmarshal(buf.Bytes(), &logOutput)
109 require.NoError(t, err)
110
111 assert.Equal(t, "INFO", logOutput["level"])
112 assert.Equal(t, "test message", logOutput["message"])
113 assert.Equal(t, "test-request-123", logOutput["requestId"])
114 assert.Equal(t, "value", logOutput["key"])
115 assert.Contains(t, logOutput, "timestamp")
116 assert.NotContains(t, logOutput, "functionArn")
117 assert.NotContains(t, logOutput, "tenantId")
118}
119
120func TestLogHandler_NoLambdaContext(t *testing.T) {
121 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 1

NewContextFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…