Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: Child Logger doesn't respect loglevel #5949

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

Closed
leandrodamascena opened this issue Jan 29, 2025 · 2 comments · Fixed by #5950
Closed

Bug: Child Logger doesn't respect loglevel #5949

leandrodamascena opened this issue Jan 29, 2025 · 2 comments · Fixed by #5950
Assignees
Labels
bug Something isn't working logger

Comments

@leandrodamascena
Copy link
Contributor

Expected Behaviour

When creating Child Loggers, it should be possible to change log level.

Default Python Library

import logging

parent_logger = logging.getLogger('parent')
parent_logger.setLevel(logging.DEBUG)

parent_handler = logging.StreamHandler()
parent_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
parent_handler.setFormatter(parent_formatter)
parent_logger.addHandler(parent_handler)
parent_logger.setLevel("INFO")

child_logger = logging.getLogger('parent.child')

child_handler = logging.StreamHandler()
child_formatter = logging.Formatter('%(name)s [%(filename)s:%(lineno)d] - %(levelname)s - %(message)s')
child_handler.setFormatter(child_formatter)
child_logger.addHandler(child_handler)
child_logger.setLevel("DEBUG")

parent_logger.debug("This is a parent logger message") # LogLevel of "parent" is INFO, won't be printed
child_logger.debug("This is a child logger message") # LogLevel of "parent.child" is DEBUG, will be printed

Powertools

from aws_lambda_powertools import Logger

logger = Logger(
    service="payment",
    location="Test1",
    level="INFO"
)

logger2 = Logger(
    service="payment",
    child=True,
    location="Test2",
    level="DEBUG" # This doesn't take effect
)

Current Behaviour

It does not respect the log level and does not emit logs if the child logger has a different log level.

Code snippet

from aws_lambda_powertools import Logger
import logging

location_format = "[%(funcName)s] %(module)s"

logger = Logger(
    service="payment",
    location=location_format,
    level="INFO"
)

logger.info("Test1")

logger2 = Logger(
    service="payment",
    child=True,
    location="Test2",
    level="DEBUG"
)

Possible Solution

No response

Steps to Reproduce

Write a function and use the code.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

Lambda Layers, PyPi

Debugging logs

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jan 29, 2025
Copy link
Contributor

This is now released under 3.6.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 11, 2025
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logger
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

1 participant