Skip to content

MNT: Prefer capitalized logging levels #30339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/devel/coding_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ If an end-user of Matplotlib sets up `logging` to display at levels more
verbose than ``logging.WARNING`` in their code with the Matplotlib-provided
helper::

plt.set_loglevel("debug")
plt.set_loglevel("DEBUG")

or manually with ::

Expand Down
2 changes: 1 addition & 1 deletion doc/devel/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mode::
git clean -xfd
git pull
python -m pip install -v . > build.out
python -c "from pylab import *; set_loglevel('debug'); plot(); show()" > run.out
python -c "from pylab import *; set_loglevel('DEBUG'); plot(); show()" > run.out

and post :file:`build.out` and :file:`run.out` to the `matplotlib-devel
<https://mail.python.org/mailman/listinfo/matplotlib-devel>`_
Expand Down
2 changes: 1 addition & 1 deletion doc/install/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ development environment such as :program:`IDLE` which add additional
complexities. Open up a UNIX shell or a DOS command prompt and run, for
example::

python -c "from pylab import *; set_loglevel('debug'); plot(); show()"
python -c "from pylab import *; set_loglevel('DEBUG'); plot(); show()"

This will give you additional information about which backends Matplotlib is
loading, version information, and more. At this point you might want to make
Expand Down
2 changes: 1 addition & 1 deletion doc/users/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ provide the following information in your e-mail to the `mailing list
* Matplotlib provides debugging information through the `logging` library, and
a helper function to set the logging level: one can call ::

plt.set_loglevel("info") # or "debug" for more info
plt.set_loglevel("INFO") # or "DEBUG" for more info

to obtain this debugging information.

Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,21 @@ def set_loglevel(level):
- set the root logger handler's level, creating the handler
if it does not exist yet

Typically, one should call ``set_loglevel("info")`` or
``set_loglevel("debug")`` to get additional debugging information.
Typically, one should call ``set_loglevel("INFO")`` or
``set_loglevel("DEBUG")`` to get additional debugging information.

Users or applications that are installing their own logging handlers
may want to directly manipulate ``logging.getLogger('matplotlib')`` rather
than use this function.

Parameters
----------
level : {"notset", "debug", "info", "warning", "error", "critical"}
The log level of the handler.
level : {"NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
The log level as defined in `Python logging levels
<https://docs.python.org/3/library/logging.html#logging-levels>`__.

For backwards compatibility, the levels are case-insensitive, but
the capitalized version is preferred in analogy to `logging.Logger.setLevel`.

Notes
-----
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
CapStyleType: TypeAlias = CapStyle | Literal["butt", "projecting", "round"]
"""Line cap styles. See :doc:`/gallery/lines_bars_and_markers/capstyle`."""

LogLevel: TypeAlias = Literal["notset", "debug", "info", "warning", "error", "critical"]
LogLevel: TypeAlias = Literal["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
"""Literal type for valid logging levels accepted by `set_loglevel()`."""

CoordsBaseType = Union[
Expand Down
Loading