Skip to content

Commit 2ea9371

Browse files
committed
MNT: Prefer capitalized logging levels
matplotlib#30302 just introduced literals for the log levels. Previously, the situation was a bit vague: While the docstring described the levels as all lowercase, in fact any casing is accepted. This PR changes the preferred casing to be all-capitalized in analogy to the logging standard library, which only supports this casing. Lowercase remains supported because it's not worth an API breakage. We might later consider to also accept logging levels directly, i.e. `logging.DEBUG` to be more congruent with the logging library. But this can be done any time. It's important to get this PR in soon to not release the typing Literal in lowercase form.
1 parent 53af231 commit 2ea9371

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

doc/devel/coding_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ If an end-user of Matplotlib sets up `logging` to display at levels more
215215
verbose than ``logging.WARNING`` in their code with the Matplotlib-provided
216216
helper::
217217

218-
plt.set_loglevel("debug")
218+
plt.set_loglevel("DEBUG")
219219

220220
or manually with ::
221221

doc/devel/troubleshooting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mode::
2323
git clean -xfd
2424
git pull
2525
python -m pip install -v . > build.out
26-
python -c "from pylab import *; set_loglevel('debug'); plot(); show()" > run.out
26+
python -c "from pylab import *; set_loglevel('DEBUG'); plot(); show()" > run.out
2727

2828
and post :file:`build.out` and :file:`run.out` to the `matplotlib-devel
2929
<https://mail.python.org/mailman/listinfo/matplotlib-devel>`_

doc/install/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ development environment such as :program:`IDLE` which add additional
179179
complexities. Open up a UNIX shell or a DOS command prompt and run, for
180180
example::
181181

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

184184
This will give you additional information about which backends Matplotlib is
185185
loading, version information, and more. At this point you might want to make

doc/users/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ provide the following information in your e-mail to the `mailing list
367367
* Matplotlib provides debugging information through the `logging` library, and
368368
a helper function to set the logging level: one can call ::
369369

370-
plt.set_loglevel("info") # or "debug" for more info
370+
plt.set_loglevel("INFO") # or "DEBUG" for more info
371371

372372
to obtain this debugging information.
373373

lib/matplotlib/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,21 @@ def set_loglevel(level):
292292
- set the root logger handler's level, creating the handler
293293
if it does not exist yet
294294
295-
Typically, one should call ``set_loglevel("info")`` or
296-
``set_loglevel("debug")`` to get additional debugging information.
295+
Typically, one should call ``set_loglevel("INFO")`` or
296+
``set_loglevel("DEBUG")`` to get additional debugging information.
297297
298298
Users or applications that are installing their own logging handlers
299299
may want to directly manipulate ``logging.getLogger('matplotlib')`` rather
300300
than use this function.
301301
302302
Parameters
303303
----------
304-
level : {"notset", "debug", "info", "warning", "error", "critical"}
305-
The log level of the handler.
304+
level : {"NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
305+
The log level as defined in `Python logging levels
306+
<https://docs.python.org/3/library/logging.html#logging-levels>`__.
307+
308+
For backwards compatibility, the levels are case-insensitive, but
309+
the capitalized version is preferred in analogy to `.Logger.setLevel`.
306310
307311
Notes
308312
-----

lib/matplotlib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
CapStyleType: TypeAlias = CapStyle | Literal["butt", "projecting", "round"]
9494
"""Line cap styles. See :doc:`/gallery/lines_bars_and_markers/capstyle`."""
9595

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

9999
CoordsBaseType = Union[

0 commit comments

Comments
 (0)