Skip to content

Commit

Permalink
fix(typing): level arg in copy_config_to_registered_loggers (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbakk authored Sep 21, 2022
1 parent 93a022c commit b6b130d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit b6b130d

Please sign in to comment.