Python Glossary Русский

all Python 3loggingfunction

logging.addLevelName()

levels

Registers a name for a numeric logging level or renames an existing one — for example, level 25 named NOTICE.

Syntax

logging.addLevelName(level, levelName)

It only links a number to a name: no logger.notice() method appears, you still write logger.log(25, ...). The name is global to the process, and addLevelName(logging.WARNING, 'WARN') renames the standard level in every log, third-party libraries included. Unregistered numbers still work, but show up as 'Level 25'.

Examples

import logging, sys
logging.basicConfig(stream=sys.stdout, format='%(levelname)s: %(message)s')
logging.log(25, 'до')  # → Level 25: до
logging.addLevelName(25, 'NOTICE')
logging.log(25, 'после')  # → NOTICE: после
print(hasattr(logging.getLogger(), 'notice'))  # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy