Python Glossary Русский

all Python 3deprecated in 3.3loggingfunction

logging.warn()

levels

Deprecated alias of logging.warning(): it logs a WARNING on the root logger and emits a DeprecationWarning.

Syntax

logging.warn(msg, *args, **kwargs)

The documentation mentions it only in a note under warning(), asking you not to use it. It logs the same as warning() but emits a DeprecationWarning on every call, visible when a script runs directly and under pytest. The fix is a few letters: warn → warning, and the same goes for the logger.warn() method.

Examples

import logging, sys, warnings
logging.basicConfig(stream=sys.stdout, format='%(levelname)s %(message)s')
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter('always')
    logging.warn('старый вызов')  # → WARNING старый вызов
print(caught[0].category.__name__)  # → DeprecationWarning

See also

Open in the full glossarydocs.python.orgReport an inaccuracy