Closed
Description
Use case
The built in logger supports adding additional context using the append_keys
and removing that additional context using the remove_keys
methods, as documented here:
https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#appending-additional-keys
Allow the built in logger to support logging keys as a context manager using the with
keyword.
Solution/User Experience
Just adding an additional method that implements the contextlib
module's contextmanager
decorator as documented here:
https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager
Example:
with logger.with_keys(some_key="some_value"):
# do something
logger.info("Something was done")
# the log output would include the 'some_key' context
# Do some other thing
logger.info("Some other thing was done")
# the log output would not include the 'some_key' context
This would reduce the need to remember to call remove_keys
when specific context no longer wants to be logged.
Alternative solutions
No response
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Metadata
Metadata
Assignees
Type
Projects
Status
Shipped