Skip to content

Commit

Permalink
Add child loggers validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Ploski committed Mar 14, 2022
1 parent 51ee897 commit e550eaa
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/functional/test_logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from enum import Enum

import pytest
from pytest_mock import MockerFixture

from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging import formatter, utils
Expand Down Expand Up @@ -195,6 +196,33 @@ def test_copy_config_to_ext_loggers_should_not_break_append_keys(stdout, log_lev
powertools_logger.append_keys(key="value")


def test_copy_config_to_ext_loggers_child_loggers_work(stdout):
# GIVEN powertools logger AND child initialized AND

# GIVEN Loggers are initialized
# create child logger before parent to mimick
# importing logger from another module/file
# as loggers are created in global scope
service = service_name()
child = Logger(stream=stdout, service=service, child=True)
parent = Logger(stream=stdout, service=service)

# WHEN a child Logger adds an additional key
child.structure_logs(append=True, customer_id="value")

# WHEN configuration copied from powertools logger
# AND powertools logger and child logger used
utils.copy_config_to_registered_loggers(source_logger=parent)
parent.warning("Logger message")
child.warning("Child logger message")

# THEN payment_id key added to both powertools logger and child logger
parent_log, child_log = capture_multiple_logging_statements_output(stdout)
assert "customer_id" in parent_log
assert "customer_id" in 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

0 comments on commit e550eaa

Please sign in to comment.