Skip to content

Commit aef767c

Browse files
mploskiMichal Ploski
and
Michal Ploski
authored
fix(logger-utils): regression on exclude set leading to no formatter (#1080)
Co-authored-by: Michal Ploski <[email protected]>
1 parent 64ab0b7 commit aef767c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

aws_lambda_powertools/logging/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def copy_config_to_registered_loggers(
4141
source_logger_name = source_logger.name.split(".")[0]
4242

4343
if exclude:
44-
exclude.update(source_logger_name, PACKAGE_LOGGER)
44+
exclude.update([source_logger_name, PACKAGE_LOGGER])
4545
else:
4646
exclude = {source_logger_name, PACKAGE_LOGGER}
4747

tests/functional/test_logger_utils.py

+22
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ def test_copy_config_to_parent_loggers_only(stdout):
217217
assert child.parent.name == service
218218

219219

220+
def test_copy_config_to_parent_loggers_only_with_exclude(stdout):
221+
# GIVEN Powertools Logger and Child Logger are initialized
222+
# and Powertools Logger config is copied over with exclude set
223+
service = service_name()
224+
child = Logger(stream=stdout, service=service, child=True)
225+
parent = Logger(stream=stdout, service=service)
226+
utils.copy_config_to_registered_loggers(source_logger=parent, exclude={"test"})
227+
228+
# WHEN either parent or child logger append keys
229+
child.append_keys(customer_id="value")
230+
parent.append_keys(user_id="value")
231+
parent.info("Logger message")
232+
child.info("Child logger message")
233+
234+
# THEN both custom keys should be propagated bi-directionally in parent and child loggers
235+
# as child logger won't be touched when config is being copied
236+
parent_log, child_log = capture_multiple_logging_statements_output(stdout)
237+
assert "customer_id" in parent_log, child_log
238+
assert "user_id" in parent_log, child_log
239+
assert child.parent.name == service
240+
241+
220242
def test_copy_config_to_ext_loggers_no_duplicate_logs(stdout, logger, log_level):
221243
# GIVEN an root logger, external logger and powertools logger initialized
222244

0 commit comments

Comments
 (0)