Repository navigation
Conversation
…_to_registered_loggers
Manishram-ai
left a comment
There was a problem hiding this comment.
Thanks for fixing this. I tried a few log_level values on develop and on this branch, and 0 now gives NOTSET while the exclude set I pass in stays the same. The one other change I found is log_level="", which falls back to the source logger's level on develop and raises ValueError: Unknown level: '' here. With the two suggestions below, the logger tests pass (207 tests), and ruff and mypy are clean.
| List of logger names to exclude, by default None | ||
| """ | ||
| level = log_level or source_logger.log_level | ||
| level = source_logger.log_level if log_level is None else log_level |
There was a problem hiding this comment.
The old log_level or source_logger.log_level treated an empty string like None. Something like log_level=os.getenv("LIBS_LOG_LEVEL", "") would start failing on cold start after an upgrade. This keeps that fallback and still honours 0.
| level = source_logger.log_level if log_level is None else log_level | |
| level = source_logger.log_level if log_level in (None, "") else log_level |
There was a problem hiding this comment.
Good catch, thanks. Applied in the latest commit: an empty string now falls back to the source logger level again, and 0 still gives NOTSET.
|
|
||
| # THEN external logger uses NOTSET instead of the source logger level | ||
| assert powertools_logger.level == log_level.CRITICAL.value | ||
| assert logger.level == log_level.NOTSET.value |
There was a problem hiding this comment.
A test for the empty string. It fails on this branch with ValueError: Unknown level: '' and passes with the change above.
| assert logger.level == log_level.NOTSET.value | |
| assert logger.level == log_level.NOTSET.value | |
| def test_copy_config_to_ext_loggers_empty_log_level_uses_source_level(stdout, logger, log_level): | |
| # GIVEN an external logger and Powertools for AWS Lambda (Python) logger initialized | |
| logger = logger() | |
| powertools_logger = Logger(service=service_name(), level=log_level.CRITICAL.value, stream=stdout) | |
| # WHEN configuration copied with an empty log_level | |
| utils.copy_config_to_registered_loggers( | |
| source_logger=powertools_logger, | |
| log_level="", | |
| include={logger.name}, | |
| ) | |
| # THEN external logger falls back to the source logger level | |
| assert logger.level == log_level.CRITICAL.value |
There was a problem hiding this comment.
Added this test too. It fails without the change and passes with it.
|
Manishram-ai
left a comment
There was a problem hiding this comment.
Thanks for adding both! An empty log_level falls back to the source logger's level again, 0 still gives NOTSET, and the logger tests pass for me on the new commit.



Issue number: closes #8829
Summary
Changes
In
aws_lambda_powertools/logging/utils.py,copy_config_to_registered_loggers:{*(exclude or ()), source_logger_name, PACKAGE_LOGGER}) instead of callingexclude.update(...)on the caller's set;log_level is Noneinstead of truthiness, solog_level=0(NOTSET) is used and no longer falls back to the source logger's level.User experience
Before:
and
log_level=0set the external loggers to the source logger's level.After:
excludeis still{"mine"}, andlog_level=0sets the external loggers toNOTSET. Calls that pass nolog_level, or a non-zero one, behave as before.Verification
I used an AI assistant (Claude) to help write this change. I ran the tests below myself.
New functional tests in
tests/functional/logger/required_dependencies/test_logger_utils.py(public API only):test_copy_config_to_ext_loggers_keeps_caller_exclude_set,test_copy_config_to_ext_loggers_log_level_notset.On
develop(fix reverted, tests kept):With the fix:
Full
uv run pytest -q tests/unit tests/functionalon this branch: 4055 passed, 73 skipped, 3 failed. The same 3 fail ondevelopwithout my change, and they come from test order, not this PR: oncetests/functional/metrics/datadogis collected,ddtraceis imported and addsdd.*keys to log records, sotest_append_context_keys_handles_empty_dictandtest_log_dict_key_strip_nonessee extra keys (both pass whentests/functional/loggerruns alone). The third,test_datadog_write_to_log_with_env_variable, passes when run alone. On my machine some full runs also hung in the Redis idempotency tests ondeveloptoo, so I ran the logger tests separately as well.ruff format --checkandruff checkon the changed files: clean.mypy aws_lambda_powertools/logging/: "Success: no issues found in 17 source files".By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.