Closed
Description
When using utils.copy_config_to_registered_loggers()
to copy the PowerLogger config to existing loggers created by a library, this results in duplicate log entries in AWS Lambda
Expected Behavior
When copying config from the AWS Powertools logger to existing loggers instantiated by a library, I expect the log statements of that library to appear once in the log stream, formatted as JSON
Current Behavior
When copying config from the AWS Powertools logger to existing loggers, I see log statements from existing loggers appearing twice in the log stream: once properly formatted as JSON and once as plain text
Possible Solution
I don't know why is this happening, so I can't really comment on a solution 😅
Steps to Reproduce (for bugs)
- Have a library that instantiates loggers the "regular" Python way, like this:
logger = logging.getLogger(__name__)
class MyClass:
def my_func():
logger.info("Hello")
- Import this library into your Lambda function
- Instantiate a logger from AWS Lambda Powertools and copy the config to existing loggers:
from aws_lambda_powertools import Logger
from mylibrary import MyClass
logger = Logger() # POWERTOOLS_SERVICE_NAME=myservice
utils.copy_config_to_registered_loggers(source_logger=logger)
- Observe duplicated logs in the Lambda log stream
Environment
- Powertools version used: 1.25.1
- Packaging format (Layers, PyPi): Docker image
- AWS Lambda function runtime: Python 3.9