What's the difference between logging.warn and logging.warning in Python?

PythonLoggingWarnings

Python Problem Overview


The samples at <http://docs.python.org/2/howto/logging.html> use both warn and warning.

Python Solutions


Solution 1 - Python

logging.warn has been deprecated since Python 3.3 and you should use logging.warning.

Prior to Python 3.3, logging.warn and logging.warning were the same function, but logging.warn was not documented, as noted in a closed issue in the Python bug tracker http://bugs.python.org/issue13235:

> That's deliberate. The original code (before incorporation into Python) had warn(), which was kept for backward compatibility. The docs refer to warning() because that's what everyone is supposed to use. The method names map to the lower case of the appropriate logging level name.

logging.warn() was kept for backwards compatibility but a deprecation warning was added. logging.warning() is what everyone is supposed to use.

Solution 2 - Python

Prior to Python 3.3, they are the same, however warn is deprecated:

>>> import logging
>>> logging.warn is logging.warning
True

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTallmadView Question on Stackoverflow
Solution 1 - Pythonsiebz0rView Answer on Stackoverflow
Solution 2 - PythonjamylakView Answer on Stackoverflow