Bug: child Logger without a level ignores its parent's log level since 3.6.0

未关闭 适合新手
#8,778 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@saimcyber 已经在做这个了。

开始于 2026年11月12日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

issue 指出子 Logger 的级别处理和 refresh_sample_rate_calculation() 是受影响的行为,但没有提供文件或测试路径。先追踪 Python 包中 Logger 的构造和采样率刷新过程,然后查找相关的 logger 测试。完成标准是:未显式指定级别的子 Logger 遵循父 Logger 配置并采样后的级别,而具有自身级别的子 Logger 保留该级别;为报告的情况添加测试。

由索引模型根据 Issue 内容生成。

描述

Expected Behaviour

A child Logger (Logger(child=True)) created without a level should follow its parent's log level: a level set in the parent's constructor, later setLevel() calls, and debug sampling. That's how it worked up to 3.5.0, and it's what the docs describe: "All state changes will be propagated bi-directionally between Child and Parent."

Current Behaviour

Since 3.6.0 (#5950), a child without a level always ends up at INFO (or at POWERTOOLS_LOG_LEVEL when that's set) and stops following its parent:

  • parent level="DEBUG", setLevel("DEBUG") or sampling_rate=1: the child's DEBUG logs are dropped
  • parent level="WARNING": the child still emits INFO
  • a child that decorates the handler with POWERTOOLS_LOGGER_SAMPLE_RATE set: every warm invocation resets it to INFO
  • child.log_level always reports 20

#5950 was meant to let a child use its own level when one is passed. It also changed children that don't pass one.

Code snippet
# shared.py
from aws_lambda_powertools import Logger

logger = Logger(child=True)  # service comes from POWERTOOLS_SERVICE_NAME=payment


def work():
    logger.debug("child debug")
    logger.info("child info")


# app.py
import shared

from aws_lambda_powertools import Logger

logger = Logger(level="DEBUG")  # same with logger.setLevel("DEBUG") or Logger(sampling_rate=1)

shared.work()
# 3.5.0:  prints "child debug" and "child info"
# 3.6.0+: prints only "child info"  <- the child's DEBUG log is lost
Possible Solution

Only call setLevel on a child when a level is passed, so it stays NOTSET and inherits like before. The same goes for the level refresh_sample_rate_calculation() restores for a child. log_level should then return the effective level, so a child reports the level it actually logs at. I have a fix with tests ready and can open a PR once this is triaged.

Steps to Reproduce
  1. Put the two files above in a folder and set POWERTOOLS_SERVICE_NAME=payment.
  2. pip install aws-lambda-powertools==3.38.0, then run python app.py: only "child info" is printed.
  3. pip install aws-lambda-powertools==3.5.0 and run it again: both lines are printed.
Did you run the reproduction yourself?

Yes, I ran it and saw the failure

Powertools for AWS Lambda (Python) version

3.38.0 (broken since 3.6.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs
Child Logger without a level, same two-module app on each version:

parent                                        3.5.0        3.6.0 - 3.38.0
level="DEBUG" / setLevel("DEBUG") / sampling  DEBUG+INFO   INFO only
sampling decorator, 2 warm invocations        both         INFO only
level="WARNING"                               nothing      child INFO leaks
child.log_level (parent DEBUG)                0            20
主要语言
Python
星标
3.3k
派生
511
平均合并
3 天 8 小时
30 天内合并 PR
103

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws-powertools/powertools-lambda-python 的其他 Issue

查看 aws-powertools/powertools-lambda-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。