Skip to content

Provide method to get list of logging level names #88024

Description

@andylowry
mannequin
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']

    Activity

    1. andylowry commented on Apr 15, 2021

      andylowrymannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 15, 2021
    3. shreyanavigyan commented on Apr 15, 2021

      shreyanavigyanmannequin
      Mannequin

      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.

    4. akulakov commented on May 17, 2021

      @akulakov
      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..

    5. andylowry commented on May 30, 2021

      andylowrymannequin
      MannequinAuthor

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

    6. rhettinger commented on May 30, 2021

      @rhettinger
      Contributor

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

      That seem like the best approach.

    7. miss-islington commented on Jun 3, 2021

      @miss-islington
      Contributor

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

    8. added
      3.11only security fixes
      and removed on Jun 3, 2021
    9. added
      3.11only security fixes
      type-featureA feature request or enhancement
      and removed on Jun 3, 2021
    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions