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: regression 104 #105

Merged
merged 9 commits into from
Aug 14, 2020
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
2 changes: 2 additions & 0 deletions .github/workflows/python_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring on line 47 above declares the LOG_LEVEL environment variable as capable of accepting an integer. That probably needs to be handled here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handling that in another PR before publishing it, as the test didn't go through

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