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

Lowercase log levels for Python #4

Open
abitrolly opened this issue Dec 25, 2019 · 1 comment
Open

Lowercase log levels for Python #4

abitrolly opened this issue Dec 25, 2019 · 1 comment

Comments

@abitrolly
Copy link
Member

The task is to make Python logging logger.setLevel() accept lowercase string. It already accepts uppercase 'DEBUG' string.

import logging

logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
logger.addHandler(handler)

logger.setLevel('DEBUG')
logger.debug('!!!')

Modifications need to be done to _checkLevel function.

https://github.com/python/cpython/blob/8c0f0016e2d39f86589187db75012238c4e760e9/Lib/logging/__init__.py#L189-L198

def _checkLevel(level):
    if isinstance(level, int):
        rv = level
    elif str(level) == level:
        if level not in _nameToLevel:
            raise ValueError("Unknown level: %r" % level)
        rv = _nameToLevel[level]
    else:
        raise TypeError("Level not an integer or a valid string: %r" % level)
    return rv
@abitrolly
Copy link
Member Author

@abitrolly abitrolly transferred this issue from yakshaveinc/tasks Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant