105

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

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Tallmad
  • 1,951
  • 4
  • 22
  • 29
  • 3
    Not the same question, but some Googlers may have been looking for: [Python warnings.warn() vs. logging.warning()](http://stackoverflow.com/questions/9595009/python-warnings-warn-vs-logging-warning) – Mark Amery Jun 25 '16 at 13:19
  • Possible duplicate: [warnings.warn() vs. logging.warning()](https://stackoverflow.com/q/9595009/6862601). – codeforester Mar 08 '21 at 23:36

2 Answers2

144

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.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
siebz0r
  • 18,867
  • 14
  • 64
  • 107
41

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

>>> import logging
>>> logging.warn is logging.warning
True
jamylak
  • 128,818
  • 30
  • 231
  • 230