Of course! This is a very common point of confusion for Python developers. Here’s a detailed breakdown of logging.warn, what happened to it, and what you should use instead.

The Short Answer (TL;DR)
Stop using logging.warn().
It has been deprecated since Python 3.2 and was removed in Python 3.13. You should use logging.warning() instead.
Correct Usage:
import logging
logging.basicConfig(level=logging.WARNING)
logging.warning("This is a warning message.")
The Detailed Explanation
The History: Why logging.warn() Existed
The logging module was originally created by Vinay Sajip. In his initial design, he chose to use British English spelling for the methods, so the method for logging warnings was logging.warn().

The Change: Why logging.warning() is Now Standard
As Python's standard library grew, there was a push to standardize on American English spellings for consistency with other modules and the broader Python community. The Python Enhancement Proposal (PEP) 8, which provides style guidelines for Python code, recommends using American English.
To facilitate this change, the logging module added the new logging.warning() method and marked the old logging.warn() as deprecated. This meant that while warn() still worked, it would issue a DeprecationWarning to let developers know they should switch to the new, preferred method.
What Happened in Python 3.13?
The Python core developers are now in the process of fully removing deprecated features to clean up the codebase. In Python 3.13, logging.warn() was officially removed. If you try to use it, you will get an AttributeError.
Practical Demonstration
Let's see the difference in behavior across Python versions.

Code to test:
import logging
import sys
# Configure basic logging to see the output
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
print(f"Running on Python {sys.version}")
try:
# This is the old, deprecated way
print("\n--- Trying to use logging.warn() ---")
logging.warn("This is a deprecated warning.")
except AttributeError as e:
print(f"AttributeError: {e}")
# This is the correct, modern way
print("\n--- Using logging.warning() (the correct way) ---")
logging.warning("This is a proper warning message.")
Expected Output:
-
On Python 3.12 or older: You will see a
DeprecationWarning(though it might be hidden by default).Running on Python 3.12.x ... --- Trying to use logging.warn() --- DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead WARNING: This is a deprecated warning. --- Using logging.warning() (the correct way) --- WARNING: This is a proper warning message. -
On Python 3.13 or newer: You will get a hard error.
Running on Python 3.13.x ... --- Trying to use logging.warn() --- AttributeError: module 'logging' has no attribute 'warn' --- Using logging.warning() (the correct way) --- WARNING: This is a proper warning message.
Best Practices for Logging in Python
Now that we've cleared up the warn vs. warning issue, here are some best practices for using the logging module effectively.
Use a Named Logger
Instead of calling logging.info() directly, it's better to get a logger specific to your module or application. This gives you more control.
# In my_module.py
import logging
# Get a logger with the name of the current module
logger = logging.getLogger(__name__)
def do_something_risky():
logger.warning("About to perform a risky operation.")
# ... do the risky operation ...
Configure Logging Properly
Don't just use basicConfig in a library. Let the application that uses your library configure the logging. If you are writing a script, basicConfig is fine for simple cases.
# In your main application script
import logging
import my_module # The module from the example above
# Configure the root logger
logging.basicConfig(
level=logging.INFO, # Set the minimum level to INFO
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("app.log"),
logging.StreamHandler() # Also print to console
]
)
my_module.do_something_risky()
Choose the Right Log Level
Use the appropriate level for the severity of the message.
logging.DEBUG: Detailed information, typically of interest only when diagnosing problems.logging.INFO: Confirmation that things are working as expected.logging.WARNING: An indication that something unexpected happened, or a problem might occur in the near future (e.g., ‘disk space low’). The software is still working as expected.logging.ERROR: Due to a more serious problem, the software has not been able to perform some function.logging.CRITICAL: A very serious error, indicating that the program itself may be unable to continue running.
Use Log Formatting
Make your logs easy to read and parse by using a format string.
%(asctime)s: Human-readable time.%(name)s: The logger's name (great for tracing where a log came from).%(levelname)s: The log level (e.g.,INFO,WARNING).%(message)s: The actual log message.
Summary
| Method | Status | Recommendation |
|---|---|---|
logging.warn() |
Deprecated (since 3.2), Removed (since 3.13) | Do not use. It will cause errors in modern Python. |
logging.warning() |
Standard | Use this. It is the correct and future-proof way to log warnings. |
