You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: matplotlib.set_loglevel() adds a console handler #23646
matplotlib.set_loglevel() adds a logging console handler which then leads to duplicate messages in application code. The best practice is to allow the application code to add the handlers to its logger along with formatting, filtering, etc. The existing #13264 attempted to address this.
True
DEBUG:matplotlib:CACHEDIR=C:\Users\ljohnsto.matplotlib
CACHEDIR=C:\Users\ljohnsto.matplotlib
DEBUG:matplotlib.font_manager:Using fontManager instance from C:\Users\ljohnsto.matplotlib\fontlist-v330.json
Using fontManager instance from C:\Users\ljohnsto.matplotlib\fontlist-v330.json
Expected outcome
False
CACHEDIR=C:\Users\ljohnsto.matplotlib
Using fontManager instance from C:\Users\ljohnsto.matplotlib\fontlist-v330.json
Additional information
The workaround is:
In [1]: importloggingIn [2]: importmatplotlibasmplIn [3]: mpl_logger=logging.getLogger("matplotlib")
In [4]: mpl.set_loglevel("debug")
In [5]: mpl_logger_handlers=mpl_logger.handlers.copy()
In [6]: forhinmpl_logger_handlers:
...: mpl_logger.removeHandler(h)
...:
In [7]: logger=logging.getLogger()
In [8]: ch=logging.StreamHandler()
In [9]: logger.addHandler(ch)
In [10]: logger.setLevel(logging.DEBUG)
In [11]: importmatplotlib.pyplotaspltCACHEDIR=C:\Users\ljohnsto\.matplotlibUsingfontManagerinstancefromC:\Users\ljohnsto\.matplotlib\fontlist-v330.json
'''
### Operating systemWindows### Matplotlib Version3.5.2### Matplotlib BackendTkAgg### Python version3.9.13### Jupyter version_Noresponse_### Installationpip
Yes agreed. But set_loglevel is meant to be a helper for endusers (eg our application) versus for downstream applications. Set matplotlibs log levels using the logging library if you have a downstream application.
The documentation for matplotlib.set_loglevel() doesn't indicate that Matplotlib is using the standard library logging. So, I thought I had to opt-in to get logging information through this function call.
It appears to me that the top level module matplotlib represents the library and matplotlib.pyplot represents the application - is this correct?
If so, perhaps move set_loglevel() to pyplot and provide a documentation section for logging generally.
A link to the standard logging library would make sense. I don't really see the point of a deprecation cycle for the top-level set_loglevel - it is already also exposed as pyplot.set_loglevel.
The documentation for matplotlib.set_loglevel() doesn't indicate that Matplotlib is using the standard library logging. So, I thought I had to opt-in to get logging information through this function call.
fair, will open a PR to fix that. I'm also thinking about adding a keyword arguement to opt-opt of us trying to install a handler.
It appears to me that the top level module matplotlib represents the library and matplotlib.pyplot represents the application - is this correct?
We have not articulated in so many words, but this seems right. Historically the distinction has been a bit fuzzy, but we are slowly pushing things towards this state.
Activity
jklymak commentedon Aug 17, 2022
Yes agreed. But set_loglevel is meant to be a helper for endusers (eg our application) versus for downstream applications. Set matplotlibs log levels using the logging library if you have a downstream application.
l-johnston commentedon Aug 19, 2022
@jklymak
logging. So, I thought I had to opt-in to get logging information through this function call.matplotlibrepresents the library andmatplotlib.pyplotrepresents the application - is this correct?jklymak commentedon Aug 19, 2022
A link to the standard logging library would make sense. I don't really see the point of a deprecation cycle for the top-level set_loglevel - it is already also exposed as
pyplot.set_loglevel.tacaswell commentedon Aug 19, 2022
fair, will open a PR to fix that. I'm also thinking about adding a keyword arguement to opt-opt of us trying to install a handler.
We have not articulated in so many words, but this seems right. Historically the distinction has been a bit fuzzy, but we are slowly pushing things towards this state.
tacaswell commentedon Oct 20, 2022
xref #23681 (comment)