diff --git a/aws_lambda_powertools/logging/logger.py b/aws_lambda_powertools/logging/logger.py index 2a4f2971248..b248055aacf 100644 --- a/aws_lambda_powertools/logging/logger.py +++ b/aws_lambda_powertools/logging/logger.py @@ -44,7 +44,7 @@ class Logger: --------------------- POWERTOOLS_SERVICE_NAME : str service name - LOG_LEVEL: str, int + LOG_LEVEL: str logging level (e.g. INFO, DEBUG) POWERTOOLS_LOGGER_SAMPLE_RATE: float samping rate ranging from 0 to 1, 1 being 100% sampling diff --git a/tests/functional/test_logger.py b/tests/functional/test_logger.py index fa804a7c979..083220ccf8c 100644 --- a/tests/functional/test_logger.py +++ b/tests/functional/test_logger.py @@ -333,3 +333,14 @@ def test_logger_level_as_int(): # THEN we should be expected int (20, in this case) assert logger.level == logging.INFO + + +def test_logger_level_env_var_as_int(monkeypatch): + # GIVEN Logger is initialized + # WHEN log level is explicitly defined via LOG_LEVEL env as int + # THEN Logger should propagate ValueError + # since env vars can only be string + # and '50' is not a correct log level + monkeypatch.setenv("LOG_LEVEL", 50) + with pytest.raises(ValueError, match="Unknown level: '50'"): + Logger()