MCPcopy
hub / github.com/aws/aws-lambda-go / ExampleNewLogger

Function ExampleNewLogger

lambdacontext/example_logger_test.go:16–25  ·  view source on GitHub ↗

ExampleNewLogger demonstrates the simplest usage of NewLogger for structured logging. The logger automatically injects requestId from Lambda context into each log record.

()

Source from the content-addressed store, hash-verified

14// ExampleNewLogger demonstrates the simplest usage of NewLogger for structured logging.
15// The logger automatically injects requestId from Lambda context into each log record.
16func ExampleNewLogger() {
17 // Set up the Lambda-aware slog logger
18 slog.SetDefault(lambdacontext.NewLogger())
19
20 lambda.Start(func(ctx context.Context) (string, error) {
21 // Use slog.InfoContext to include Lambda context in logs
22 slog.InfoContext(ctx, "processing request", "action", "example")
23 return "success", nil
24 })
25}
26
27// ExampleNewLogHandler demonstrates using NewLogHandler for more control.
28func ExampleNewLogHandler() {

Callers

nothing calls this directly

Calls 2

NewLoggerFunction · 0.92
StartFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…