You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide method to get list of logging level names #88024
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=<Date2021-06-03.08:59:30.308>created_at=<Date2021-04-15.17:46:57.939>labels= ['type-feature', 'library', '3.11']
title='Provide method to get list of logging level names'updated_at=<Date2021-06-03.08:59:30.303>user='https://github.com/andylowry'
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.
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.
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 commented on May 30, 2021
andylowrymannequin
MannequinAuthor
More actions
@andrei.avk Yes, that sounds just fine. Many thanks.
Activity
andylowry commentedon Apr 15, 2021
It would be useful to have something like a
getLevelNamesmethod to return the current list of level names, ordered by priority.This currently appears to be available only by accessing a private member, like
_levelToNameor_nameToLevel.This functionality is useful, for example, in populating a
choiceslist for anargparseoption to allow a user to select a logging level when launching a program from a command line.shreyanavigyan commentedon 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 commentedon May 17, 2021
I can add getLevelNamesDict() which would return a copy of _nameToLevel, which is currently
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 commentedon May 30, 2021
@andrei.avk Yes, that sounds just fine. Many thanks.
rhettinger commentedon May 30, 2021
That seem like the best approach.
miss-islington commentedon Jun 3, 2021
New changeset 8b93f0e by andrei kulakov in branch 'main':
bpo-43858: Add logging.getLevelNamesMapping() (GH-26459)
8b93f0e