ExampleNewLogger demonstrates the simplest usage of NewLogger for structured logging. The logger automatically injects requestId from Lambda context into each log record.
()
| 14 | // ExampleNewLogger demonstrates the simplest usage of NewLogger for structured logging. |
| 15 | // The logger automatically injects requestId from Lambda context into each log record. |
| 16 | func 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. |
| 28 | func ExampleNewLogHandler() { |