Title: [Bug]: matplotlib.set_loglevel() adds a console handler · Issue #23646 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: matplotlib.set_loglevel() adds a console handler · Issue #23646 · matplotlib/matplotlib
X Title: [Bug]: matplotlib.set_loglevel() adds a console handler · Issue #23646 · matplotlib/matplotlib
Description: Bug summary 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, ...
Open Graph Description: Bug summary 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 handle...
X Description: Bug summary 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 handle...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/23646
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: matplotlib.set_loglevel() adds a console handler","articleBody":"### Bug summary\n\nmatplotlib.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.\n\n### Code for reproduction\n\n```python\nimport logging\r\nimport matplotlib as mpl\r\nmpl_logger = logging.getLogger(\"matplotlib\")\r\nmpl.set_loglevel(\"debug\")\r\nmpl_logger.hasHandlers()\r\nlogger = logging.getLogger()\r\nch = logging.StreamHandler()\r\nlogger.addHandler(ch)\r\nlogger.setLevel(logging.DEBUG)\r\nimport matplotlib.pyplot as plt\n```\n\n\n### Actual outcome\n\nTrue\r\nDEBUG:matplotlib:CACHEDIR=C:\\Users\\ljohnsto\\.matplotlib\r\nCACHEDIR=C:\\Users\\ljohnsto\\.matplotlib\r\nDEBUG:matplotlib.font_manager:Using fontManager instance from C:\\Users\\ljohnsto\\.matplotlib\\fontlist-v330.json\r\nUsing fontManager instance from C:\\Users\\ljohnsto\\.matplotlib\\fontlist-v330.json\n\n### Expected outcome\n\nFalse\r\nCACHEDIR=C:\\Users\\ljohnsto\\.matplotlib\r\nUsing fontManager instance from C:\\Users\\ljohnsto\\.matplotlib\\fontlist-v330.json\n\n### Additional information\n\nThe workaround is:\r\n```python\r\nIn [1]: import logging\r\nIn [2]: import matplotlib as mpl\r\nIn [3]: mpl_logger = logging.getLogger(\"matplotlib\")\r\nIn [4]: mpl.set_loglevel(\"debug\")\r\nIn [5]: mpl_logger_handlers = mpl_logger.handlers.copy()\r\nIn [6]: for h in mpl_logger_handlers:\r\n ...: mpl_logger.removeHandler(h)\r\n ...:\r\nIn [7]: logger = logging.getLogger()\r\nIn [8]: ch = logging.StreamHandler()\r\nIn [9]: logger.addHandler(ch)\r\nIn [10]: logger.setLevel(logging.DEBUG)\r\nIn [11]: import matplotlib.pyplot as plt\r\nCACHEDIR=C:\\Users\\ljohnsto\\.matplotlib\r\nUsing fontManager instance from C:\\Users\\ljohnsto\\.matplotlib\\fontlist-v330.json\r\n'''\n\n### Operating system\n\nWindows\n\n### Matplotlib Version\n\n3.5.2\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.9.13\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/l-johnston","@type":"Person","name":"l-johnston"},"datePublished":"2022-08-17T09:30:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/23646/matplotlib/issues/23646"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:090d9018-a1d7-dfe7-88dc-13a65f4ce8be |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DED4:139708:4878C19:65CDC5F:6A50EC76 |
| html-safe-nonce | e466a23d5f0a6a8c1c2e988317c1a63d8c5a2b24cca430a65180aedb7ebe9d09 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUQ0OjEzOTcwODo0ODc4QzE5OjY1Q0RDNUY6NkE1MEVDNzYiLCJ2aXNpdG9yX2lkIjoiNDMzMDY2MDc0ODA1MTE0Nzg5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2b47dae80bf6089795034cd45d3317aa4ec50d95d451ff8f2a6053c0054b1869 |
| hovercard-subject-tag | issue:1341460120 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/23646/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04bb3556cfcae308c7250128eaae420030fb1253854ec697e24eaf8c18d5baae/matplotlib/matplotlib/issues/23646 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04bb3556cfcae308c7250128eaae420030fb1253854ec697e24eaf8c18d5baae/matplotlib/matplotlib/issues/23646 |
| og:image:alt | Bug summary 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 handle... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | l-johnston |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fb19d617b534959801b4b7453938ecf1dfa22131 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width