Skip to content

Bug: Child Logger doesn't respect loglevel #5949

Closed

Description

@leandrodamascena

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

Activity

  1. added
    bug
    on Jan 29, 2025
  2. github-actions commented on Jan 29, 2025

    @github-actions
    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.

  3. added
    pending-release
    on Jan 29, 2025
  4. github-actions commented on Feb 11, 2025

    @github-actions
    Contributor

    This is now released under 3.6.0 version!

  5. removed
    pending-release
    on Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buglogger

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions