Skip to content
6 changes: 6 additions & 0 deletions Doc/library/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,12 @@ functions.
.. note:: If you are thinking of defining your own levels, please see the
section on :ref:`custom-levels`.

.. function:: getLevelNamesDict()

Returns the dictionary of all available level names and respective logging levels.

.. versionadded:: 3.11

.. function:: getLevelName(level)

Returns the textual or numeric representation of logging level *level*.
Expand Down
19 changes: 11 additions & 8 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@


__all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO',
'LogRecord', 'Logger', 'LoggerAdapter', 'NOTSET', 'NullHandler',
'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig',
'captureWarnings', 'critical', 'debug', 'disable', 'error',
'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass',
'info', 'log', 'makeLogRecord', 'setLoggerClass', 'shutdown',
'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory',
'lastResort', 'raiseExceptions']
'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO',
'LogRecord', 'Logger', 'LoggerAdapter', 'NOTSET', 'NullHandler',
'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig',
'captureWarnings', 'critical', 'debug', 'disable', 'error',
'exception', 'fatal', 'getLevelNamesDict', 'getLevelName', 'getLogger',
'getLoggerClass', 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'shutdown',
'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory',
'lastResort', 'raiseExceptions']

import threading

Expand Down Expand Up @@ -116,6 +116,9 @@
'NOTSET': NOTSET,
}

def getLevelNamesDict():
return _nameToLevel.copy()

def getLevelName(level):
"""
Return the textual or numeric representation of logging level 'level'.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a function that returns a copy of a dict of logging levels: func::`logging.getLevelNamesDict()`