Issue43858
Created on 2021-04-15 17:46 by andylowry, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 26459 | merged | andrei.avk, 2021-05-31 04:46 | |
| Messages (6) | |||
|---|---|---|---|
| msg391145 - (view) | Author: Andy Lowry (andylowry) | Date: 2021-04-15 17:46 | |
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. |
|||
| msg391147 - (view) | Author: Shreyan Avigyan (shreyanavigyan) * | Date: 2021-04-15 18:13 | |
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. |
|||
| msg393833 - (view) | Author: Andrei Kulakov (andrei.avk) * ![]() |
Date: 2021-05-17 21:22 | |
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..
|
|||
| msg394764 - (view) | Author: Andy Lowry (andylowry) | Date: 2021-05-30 14:31 | |
@andrei.avk Yes, that sounds just fine. Many thanks. |
|||
| msg394765 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2021-05-30 14:46 | |
> I can add getLevelNamesDict() which would return a copy of _nameToLevel That seem like the best approach. |
|||
| msg394989 - (view) | Author: miss-islington (miss-islington) | Date: 2021-06-03 08:13 | |
New changeset 8b93f0e696d3fc60fd311c13d5238da73a35e3b3 by andrei kulakov in branch 'main': bpo-43858: Add logging.getLevelNamesMapping() (GH-26459) https://github.com/python/cpython/commit/8b93f0e696d3fc60fd311c13d5238da73a35e3b3 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:44 | admin | set | github: 88024 |
| 2021-06-03 08:59:30 | vinay.sajip | set | status: open -> closed type: enhancement stage: patch review -> resolved resolution: fixed versions: + Python 3.11, - Python 3.8 |
| 2021-06-03 08:13:16 | miss-islington | set | nosy:
+ miss-islington messages: + msg394989 |
| 2021-05-31 04:46:42 | andrei.avk | set | keywords:
+ patch stage: patch review pull_requests: + pull_request25054 |
| 2021-05-30 14:46:03 | rhettinger | set | assignee: vinay.sajip messages:
+ msg394765 |
| 2021-05-30 14:31:47 | andylowry | set | messages: + msg394764 |
| 2021-05-17 21:22:42 | andrei.avk | set | nosy:
+ andrei.avk messages: + msg393833 |
| 2021-04-15 18:15:01 | eric.smith | set | nosy:
+ vinay.sajip |
| 2021-04-15 18:13:38 | eric.smith | set | nosy:
+ eric.smith |
| 2021-04-15 18:13:05 | shreyanavigyan | set | nosy:
+ shreyanavigyan messages: + msg391147 |
| 2021-04-15 17:46:57 | andylowry | create | |

