Adding structured logging helper by anzheyazzz · Pull Request #614 · aws/aws-lambda-go · GitHub
Skip to content

Adding structured logging helper#614

Merged
bmoffatt merged 4 commits into
aws:mainfrom
anzheyazzz:structured-logging
Jan 15, 2026
Merged

Adding structured logging helper#614
bmoffatt merged 4 commits into
aws:mainfrom
anzheyazzz:structured-logging

Conversation

@anzheyazzz

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Adding helper for structured logging so users can log as JSON with slog easier than before.
LogFormatName and LogLevelName are added to context.go as well so it can be easier and cleaner to setup a structured logger as well.

Tests:

Added tests for logger.go

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter

codecov-commenter commented Jan 14, 2026

Copy link
Copy Markdown

Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/logger.go
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/context.go Outdated
- Rename Handler() to LogHandler()
- Rename LogFormatName/LogLevelName to LogFormat/LogLevel
- Use functional options pattern with WithFields()
- Use Field functions (FieldFunctionARN, FieldTenantID) for immutability
- Add example tests in separate file with go1.21 build tag
Comment thread lambdacontext/logger.go Outdated
Comment thread lambdacontext/example_logger_test.go Outdated
Comment thread lambdacontext/example_logger_test.go Outdated
Comment thread lambdacontext/logger.go Outdated
bmoffatt
bmoffatt previously approved these changes Jan 15, 2026

@bmoffatt bmoffatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread lambdacontext/context.go Outdated
Comment thread lambdacontext/logger.go
@bmoffatt bmoffatt merged commit 9dac8a5 into aws:main Jan 15, 2026
27 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants