Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68379
| Date | 2014-03-15 21:58 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Clearing out handlers in logging? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8159.1394938715.18130.python-list@python.org> (permalink) |
The current (2.7; maybe 3.x?) logging module doesn't have any sort of "clear out all the current handlers" method. I can hack it by doing log = logging.getLogger() # get the root logger del log.handlers[:] # reach inside and nuke 'em log.addHandler(...) # install the one(s) I want but it feels a little dirty to reach into logging.root.handlers since there are other methods for adding/removing handlers. However, as best I can tell, to remove a handler, you already need to have it saved somewhere. Is there a better way to do this, or do I just suck it up and deal with the (potentially thread-ignorant, as it doesn't lock) hack? Thanks, -tkc
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Clearing out handlers in logging? Tim Chase <python.list@tim.thechases.com> - 2014-03-15 21:58 -0500
Re: Clearing out handlers in logging? Gunther Dietrich <gd.usenet@spamfence.net> - 2014-03-16 09:39 +0100
Re: Clearing out handlers in logging? Chris Angelico <rosuav@gmail.com> - 2014-03-16 20:02 +1100
Re: Clearing out handlers in logging? Peter Otten <__peter__@web.de> - 2014-03-16 10:18 +0100
Re: Clearing out handlers in logging? Chris Angelico <rosuav@gmail.com> - 2014-03-16 20:35 +1100
Re: Clearing out handlers in logging? Tim Chase <python.list@tim.thechases.com> - 2014-03-16 07:57 -0500
Re: Clearing out handlers in logging? Gunther Dietrich <gd.usenet@spamfence.net> - 2014-03-16 19:29 +0100
Re: Clearing out handlers in logging? Tim Chase <python.list@tim.thechases.com> - 2014-03-16 13:50 -0500
csiph-web