Skip to content

Commit

Permalink
fix: regression 104 (#105)
Browse files Browse the repository at this point in the history
* chore: trigger docs on new release

* chore: trigger docs on new release (#102) (#103)

* chore: fix test level typo

* fix: add test covering logging constant

* fix: return log level int immediately
  • Loading branch information
heitorlessa authored Aug 14, 2020
2 parents 5a08b68 + a46ebb2 commit 4573716
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <service>.<caller_file_name>, False by default
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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=[
Expand Down
13 changes: 11 additions & 2 deletions tests/functional/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,19 @@ 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

0 comments on commit 4573716

Please sign in to comment.