-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Add a restart option to logging.basicConfig() #78078
Comments
Once a logger or basicConfig() has been called, later calls to basicConfig() are silent ignored. The makes it very difficult to experiment with or teach the various options at the interactive prompt or in a Jupyter notebook. What we have: >>> import logging
>>> logging.warning('Too much data')
WARNING:root:Too much data
>>> logging.info('Volume is at 80%')
>>> logging.basicConfig(level=logging.INFO)
>>> logging.info('Volume is at 80%')
>>> # Note, no output was created What we need: >>> import logging
>>> logging.warning('Too much data')
WARNING:root:Too much data
>>> logging.info('Volume is at 80%')
>>> logging.basicConfig(level=logging.INFO, restart=True)
>>> logging.info('Volume is at 80%')
INFO:rootVolume is at 80% |
Can I take a look at this issue? One question, if we pass the restart keyword as true, should we clear all handlers before we call basicConfig?, or should we maintain it? |
You would just clear all handlers added to the root logger before calling the existing code:
Of course, test case, documentation etc. needs to be added as well. Not sure if "restart" is the best name, as it implies more than we're doing here. Similarly for "reset". IMO "force" might be better as the keyword argument name. Raymond, what do you think about "force" from a pedagogical point of view? |
"force" +1 |
"force" is also good. Perhaps "clear_handlers" or "replace_handlers" would be more self-descriptive. |
Except that it doesn't *just* clear the handlers - the act of clearing also lets e.g. the level to be set and the formatting to be set by the call. |
Not sure what the best word would be (freshen, update, reconfigure, reset, and restart all communicate the intent). I can't think of a simple word that accurately describes the implementation which removes and closes all root handlers. |
OK, let's go with "force", then. There are plenty of other places in Python where it's used, so there's that: |
Thank you! So, I'll tread lightly, advance to 3.7.0, and keep the latest 3.8.* around for surprises. Regards to you-all in the development front lines. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: