Skip to content

Bug: Logger constructor ignores level argument after first call #5591

@dennis-benchling

Description

@dennis-benchling

Expected Behaviour

According to the docs, we should be able to set the log level explicitly through the level parameter to Logger.

Current Behaviour

The level parameter is properly set the first time you instantiate Logger, but subsequent instantiations with the same service name will not set the log level. (It will always be the original value from the first instance.)

Code snippet

from aws_lambda_powertools import Logger

first = Logger(level="INFO")
second = Logger(level="DEBUG")

print(f"first level = {first.log_level}") # first level = 20
print(f"second level = {second.log_level}") # second level = 20. (Should be 10)

Possible Solution

In Logger._init_logger, setLevel should be called before the early return.

Steps to Reproduce

Run the following code:

from aws_lambda_powertools import Logger

first = Logger(level="INFO")
second = Logger(level="DEBUG")

print(f"first level = {first.log_level}") # first level = 20
print(f"second level = {second.log_level}") # second level = 20. (Should be 10)

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.8

Packaging format used

PyPi

Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions