msg319911 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2018-06-18 20:39 |
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% |
|
|
msg320196 - (view) |
Author: Dong-hee Na (corona10) *  |
Date: 2018-06-21 17:33 |
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? |
|
|
msg320218 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2018-06-22 07:39 |
You would just clear all handlers added to the root logger before calling the existing code: try: # new code to be added, not tested for h in root.handlers[:]: root.removeHandler(h) h.close() # existing code if len(root.handlers) == 0: handlers = kwargs.pop("handlers", None) 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? |
|
|
msg320219 - (view) |
Author: Dong-hee Na (corona10) *  |
Date: 2018-06-22 08:03 |
"force" +1 |
|
|
msg320321 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2018-06-23 19:10 |
> Raymond, what do you think about "force" from a pedagogical > point of view? "force" is also good. Perhaps "clear_handlers" or "replace_handlers" would be more self-descriptive. |
|
|
msg320338 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2018-06-23 22:41 |
> 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. |
|
|
msg320340 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2018-06-23 23:57 |
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. |
|
|
msg320355 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2018-06-24 05:42 |
OK, let's go with "force", then. There are plenty of other places in Python where it's used, so there's that: https://github.com/python/cpython/search?l=Python&q=force |
|
|
msg320396 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2018-06-25 04:11 |
New changeset cf67d6a934b51b1f97e72945b596477b271f70b8 by Vinay Sajip (Dong-hee Na) in branch 'master': bpo-33897: Add a 'force' keyword argument to logging.basicConfig(). (GH-7873) https://github.com/python/cpython/commit/cf67d6a934b51b1f97e72945b596477b271f70b8 |
|
|
msg321496 - (view) |
Author: michael kearney (michael.kearney) * |
Date: 2018-07-11 19:12 |
Thank you! I just stumbled into this problem with logging.basicConfig. In the course of trying to find an acceptable workaround I discovered issue 33897 . I downloaded 3.8.0 and voila my problem is solved. 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. -m Is it acceptable to express appreciation in here? |
|
|