diff --git a/.github/workflows/python_docs.yml b/.github/workflows/python_docs.yml index 86a2dd3c208..febee05519d 100644 --- a/.github/workflows/python_docs.yml +++ b/.github/workflows/python_docs.yml @@ -9,6 +9,8 @@ on: - master # Disabled until docs support versioning per branch/release # - develop + release: + types: [published] # update Docs upon new release jobs: docs: diff --git a/CHANGELOG.md b/CHANGELOG.md index be11a7b9867..655762a5611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.1] - 2020-08-14 +### Fixed +- **Logger**: Regression on `Logger` level not accepting `int` i.e. `Logger(level=logging.INFO)` + ## [1.1.0] - 2020-08-14 ### Added - **Logger**: Support for logger inheritance with `child` parameter diff --git a/aws_lambda_powertools/logging/logger.py b/aws_lambda_powertools/logging/logger.py index 1b4f3d8bcfe..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 @@ -53,7 +53,7 @@ class Logger: ---------- service : str, optional service name to be appended in logs, by default "service_undefined" - level : str, optional + level : str, int optional logging.level, by default "INFO" child: bool, optional create a child Logger named ., False by default @@ -132,8 +132,11 @@ def __getattr__(self, name): # https://github.com/awslabs/aws-lambda-powertools-python/issues/97 return getattr(self._logger, name) - def _get_log_level(self, level: str): + def _get_log_level(self, level: Union[str, int]) -> Union[str, int]: """ Returns preferred log level set by the customer in upper case """ + if isinstance(level, int): + return level + log_level: str = level or os.getenv("LOG_LEVEL") log_level = log_level.upper() if log_level is not None else logging.INFO diff --git a/pyproject.toml b/pyproject.toml index 978696e090a..ea087088993 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aws_lambda_powertools" -version = "1.1.0" +version = "1.1.1" description = "Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric" authors = ["Amazon Web Services"] classifiers=[ diff --git a/tests/functional/test_logger.py b/tests/functional/test_logger.py index 21f25125283..083220ccf8c 100644 --- a/tests/functional/test_logger.py +++ b/tests/functional/test_logger.py @@ -317,10 +317,30 @@ def test_logger_level_case_insensitive(stdout): assert logger.level == logging.INFO -def test_logger_level_not_set(stdout): +def test_logger_level_not_set(): # GIVEN a Loggers is initialized # WHEN no log level was passed - logger = Logger(level="info") + logger = Logger() # THEN we should default to INFO assert logger.level == logging.INFO + + +def test_logger_level_as_int(): + # GIVEN a Loggers is initialized + # WHEN log level is int + logger = Logger(level=logging.INFO) + + # 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()