Skip to content

copy_config_to_registered_loggers results in duplicate logs when using with existing loggers #1073

Closed
@DonDebonair

Description

@DonDebonair

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

image

Possible Solution

I don't know why is this happening, so I can't really comment on a solution 😅

Steps to Reproduce (for bugs)

  1. Have a library that instantiates loggers the "regular" Python way, like this:
logger = logging.getLogger(__name__)

class MyClass:
    def my_func():
        logger.info("Hello")
  1. Import this library into your Lambda function
  2. 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)
  1. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions