Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dennis-benchling opened this issue Nov 19, 2024 · 1 comment
Open
Labels
bug Something isn't working triage Pending triage from maintainers

Comments

@dennis-benchling
Copy link

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

@dennis-benchling dennis-benchling added bug Something isn't working triage Pending triage from maintainers labels Nov 19, 2024
Copy link

boring-cyborg bot commented Nov 19, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Pending triage from maintainers
Projects
Development

No branches or pull requests

1 participant