Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logger-utils): regression on exclude set leading to no formatter #1080

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_lambda_powertools/logging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def copy_config_to_registered_loggers(
source_logger_name = source_logger.name.split(".")[0]

if exclude:
exclude.update(source_logger_name, PACKAGE_LOGGER)
exclude.update([source_logger_name, PACKAGE_LOGGER])
else:
exclude = {source_logger_name, PACKAGE_LOGGER}

Expand Down
22 changes: 22 additions & 0 deletions tests/functional/test_logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ def test_copy_config_to_parent_loggers_only(stdout):
assert child.parent.name == service


def test_copy_config_to_parent_loggers_only_with_exclude(stdout):
# GIVEN Powertools Logger and Child Logger are initialized
# and Powertools Logger config is copied over with exclude set
service = service_name()
child = Logger(stream=stdout, service=service, child=True)
parent = Logger(stream=stdout, service=service)
utils.copy_config_to_registered_loggers(source_logger=parent, exclude={"test"})

# WHEN either parent or child logger append keys
child.append_keys(customer_id="value")
parent.append_keys(user_id="value")
parent.info("Logger message")
child.info("Child logger message")

# THEN both custom keys should be propagated bi-directionally in parent and child loggers
# as child logger won't be touched when config is being copied
parent_log, child_log = capture_multiple_logging_statements_output(stdout)
assert "customer_id" in parent_log, child_log
assert "user_id" in parent_log, child_log
assert child.parent.name == service


def test_copy_config_to_ext_loggers_no_duplicate_logs(stdout, logger, log_level):
# GIVEN an root logger, external logger and powertools logger initialized

Expand Down