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(typing): level arg in copy_config_to_registered_loggers #1534

Merged
merged 2 commits into from
Sep 21, 2022
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
4 changes: 2 additions & 2 deletions aws_lambda_powertools/logging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def copy_config_to_registered_loggers(
source_logger: Logger,
log_level: Optional[str] = None,
log_level: Optional[Union[int, str]] = None,
exclude: Optional[Set[str]] = None,
include: Optional[Set[str]] = None,
) -> None:
Expand All @@ -19,7 +19,7 @@ def copy_config_to_registered_loggers(
----------
source_logger : Logger
Powertools Logger to copy configuration from
log_level : str, optional
log_level : Union[int, str], optional
Logging level to set to registered loggers, by default uses source_logger logging level
include : Optional[Set[str]], optional
List of logger names to include, by default all registered loggers are included
Expand Down
8 changes: 5 additions & 3 deletions tests/functional/test_logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,17 @@ def test_copy_config_to_ext_loggers_clean_old_handlers(stdout, logger, log_level
assert isinstance(logger.handlers[0].formatter, formatter.LambdaPowertoolsFormatter)


def test_copy_config_to_ext_loggers_custom_log_level(stdout, logger, log_level):
@pytest.mark.parametrize("level_to_set", ["WARNING", 30])
def test_copy_config_to_ext_loggers_custom_log_level(stdout, logger, log_level, level_to_set):
# GIVEN an external logger and powertools logger initialized
logger = logger()
powertools_logger = Logger(service=service_name(), level=log_level.CRITICAL.value, stream=stdout)
level = log_level.WARNING.name

# WHEN configuration copied from powertools logger to INCLUDED external logger
# AND external logger used with custom log_level
utils.copy_config_to_registered_loggers(source_logger=powertools_logger, include={logger.name}, log_level=level)
utils.copy_config_to_registered_loggers(
source_logger=powertools_logger, include={logger.name}, log_level=level_to_set
)
msg = "test message4"
logger.warning(msg)
log = capture_logging_output(stdout)
Expand Down