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

Provide method to get list of logging level names #88024

Closed
andylowry mannequin opened this issue Apr 15, 2021 · 6 comments
Closed

Provide method to get list of logging level names #88024

andylowry mannequin opened this issue Apr 15, 2021 · 6 comments
Assignees
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@andylowry
Copy link
Mannequin

andylowry mannequin commented Apr 15, 2021

BPO 43858
Nosy @rhettinger, @vsajip, @ericvsmith, @miss-islington, @akulakov, @shreyanavigyan, @andylowry
PRs
  • bpo-43858: Add logging.getLevelNamesMapping() #26459
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/vsajip'
    closed_at = <Date 2021-06-03.08:59:30.308>
    created_at = <Date 2021-04-15.17:46:57.939>
    labels = ['type-feature', 'library', '3.11']
    title = 'Provide method to get list of logging level names'
    updated_at = <Date 2021-06-03.08:59:30.303>
    user = 'https://github.com/andylowry'

    bugs.python.org fields:

    activity = <Date 2021-06-03.08:59:30.303>
    actor = 'vinay.sajip'
    assignee = 'vinay.sajip'
    closed = True
    closed_date = <Date 2021-06-03.08:59:30.308>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2021-04-15.17:46:57.939>
    creator = 'andylowry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43858
    keywords = ['patch']
    message_count = 6.0
    messages = ['391145', '391147', '393833', '394764', '394765', '394989']
    nosy_count = 7.0
    nosy_names = ['rhettinger', 'vinay.sajip', 'eric.smith', 'miss-islington', 'andrei.avk', 'shreyanavigyan', 'andylowry']
    pr_nums = ['26459']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43858'
    versions = ['Python 3.11']

    @andylowry
    Copy link
    Mannequin Author

    andylowry mannequin commented Apr 15, 2021

    It would be useful to have something like a getLevelNames method to return the current list of level names, ordered by priority.

    This currently appears to be available only by accessing a private member, like _levelToName or _nameToLevel.

    This functionality is useful, for example, in populating a choices list for an argparse option to allow a user to select a logging level when launching a program from a command line.

    @andylowry andylowry mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir labels Apr 15, 2021
    @shreyanavigyan
    Copy link
    Mannequin

    shreyanavigyan mannequin commented Apr 15, 2021

    I agree with you. It would be nice to have a function to list or dictionary of level names. Moreover I suggest that there should be an argument to the function like format_level which can take in "dict:level_name" for returning a dictionary with the level as keys and name as values, "dict:name_level" for returning a dictionary with the name as keys and level as values or "list" for returning just the list of level names ordered by priority.

    @akulakov
    Copy link
    Contributor

    I can add getLevelNamesDict() which would return a copy of _nameToLevel, which is currently

    _nameToLevel = {
        'CRITICAL': CRITICAL,
        'FATAL': FATAL,
        'ERROR': ERROR,
        'WARN': WARNING,
        'WARNING': WARNING,
        'INFO': INFO,
        'DEBUG': DEBUG,
        'NOTSET': NOTSET,
    }

    I think it may be best not to return a list of levels because it's not obvious that some of them are aliases, if the caller is responsible for making the list out of the dict, they will be able to decide how to deal with alias levels.

    If that sounds good I can make a PR..

    @andylowry
    Copy link
    Mannequin Author

    andylowry mannequin commented May 30, 2021

    @andrei.avk Yes, that sounds just fine. Many thanks.

    @rhettinger
    Copy link
    Contributor

    I can add getLevelNamesDict() which would return a copy of _nameToLevel

    That seem like the best approach.

    @miss-islington
    Copy link
    Contributor

    New changeset 8b93f0e by andrei kulakov in branch 'main':
    bpo-43858: Add logging.getLevelNamesMapping() (GH-26459)
    8b93f0e

    @vsajip vsajip added 3.11 only security fixes and removed 3.8 only security fixes labels Jun 3, 2021
    @vsajip vsajip closed this as completed Jun 3, 2021
    @vsajip vsajip added 3.11 only security fixes type-feature A feature request or enhancement and removed 3.8 only security fixes labels Jun 3, 2021
    @vsajip vsajip closed this as completed Jun 3, 2021
    @vsajip vsajip added the type-feature A feature request or enhancement label Jun 3, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants