-
Notifications
You must be signed in to change notification settings - Fork 435
Labels
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped
Milestone
Relationships
Development
Select code repository
Activity
github-actions commentedon Jan 29, 2025
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 commentedon Feb 11, 2025
This is now released under 3.6.0 version!