Skip to content

Regression of support for log level constants #104

Closed
@zroger

Description

@zroger

Before #99 it was possible to pass a logging constant like logging.INFO to the Logger constructor. After #99, I get this exception: AttributeError: 'int' object has no attribute 'upper' from logging/logger.py:122.

The docstrings are also confusing, since the environment variable says it accepts and integer or a string, but the constructor parameter is a string.

Expected Behavior

  • The Logger constructor should accept logging constants (integers) as well as strings.
  • The environment variable and constructor arg for log level should be consistent
  • The docstrings should be consistent with the code

Current Behavior

When an integer is passed, there is an AttributeError.

Steps to Reproduce (for bugs)

>>> import logging
>>> from aws_lambda_powertools import Logger
>>> Logger(service="demo", level=logging.INFO)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/aws_lambda_powertools/logging/logger.py", line 122, in __init__
    self.log_level = self._get_log_level(level)
  File "/usr/local/lib/python3.8/site-packages/aws_lambda_powertools/logging/logger.py", line 138, in _get_log_level
    log_level = log_level.upper() if log_level is not None else logging.INFO
AttributeError: 'int' object has no attribute 'upper'

Environment

  • Powertools version used: 1.1.0
  • Packaging format (Layers, PyPi):
  • AWS Lambda function runtime: python3.8
  • Debugging logs

Activity

added
bugSomething isn't working
triagePending triage from maintainers
on Aug 14, 2020
heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

Looking into this now...

self-assigned this
on Aug 14, 2020
heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

Just managed to reproduce in a quick test - Working on a fix and should be upstream shortly. Thanks for raising this quickly @zroger

heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

PR: #105

Updating Changelog, and reviewing your comment on docstring before I publish it

heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

What it's quite odd is monkeypatch when creating a test for env var it always casts the value as string despite setting as int -- Can't reproduce in zsh/bash tho

def test_logger_level_env_var_as_int(monkeypatch):
    # GIVEN Logger is initialized
    # WHEN log level is set as int defined via LOG_LEVEL env
    monkeypatch.setenv("LOG_LEVEL", 50)
    logger = Logger()

    # THEN log level should be equals to 50 => CRITICAL
    assert logger.level == logging.CRITICAL

I'll continue on digging.

UPDATE: It's an issue with test runner which converts all int value in env var to str. I'll send a PR to cater for integer env var w/o a test, and will push a test later as it won't impact the release either way.

UPDATE 2: Take this back. Environment variables cannot be integer but string hence Pytest runner implicitly converting it and emitting a warning. Just created a fresh Sam build, and it's always string. Created a fresh docker container to verify under python image while overriding entrypoint and it's the same behaviour. Re-adding the LOG_LEVEL env var docstring to str only.

zroger

zroger commented on Aug 14, 2020

@zroger
Author

Thanks for handling this so quickly

heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

Published to PyPi but seems to be taking longer than the usual to reflect 1.1.1 - Will circle back here once it's through

heitorlessa

heitorlessa commented on Aug 14, 2020

@heitorlessa
Contributor

Damn page cache haha just managed to install by passing the latest version directly: pip install aws-lambda-powertools==1.1.1

Lemme know if that works for you and we can close this -- Thank you @zroger again for reporting it

image

added and removed
triagePending triage from maintainers
on Aug 15, 2020
heitorlessa

heitorlessa commented on Aug 16, 2020

@heitorlessa
Contributor

Alright, I'm closing this now as tests are covering this now, and have just released 1.1.2 to address PyCharm/VSCode Jedi Language Server autocomplete issue -- PyPi is operating as expected now

3 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneed-more-informationPending information to continue

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @zroger@heitorlessa

      Issue actions

        Regression of support for log level constants · Issue #104 · aws-powertools/powertools-lambda-python