Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'root': 0.05; 'method.': 0.07; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'handler,': 0.16; 'handlers.': 0.16; 'logger': 0.16; 'somewhere.': 0.16; 'subject:Clearing': 0.16; 'thanks,': 0.17; 'module': 0.19; 'hack': 0.22; 'install': 0.23; 'sort': 0.25; 'logging': 0.26; "doesn't": 0.30; 'maybe': 0.34; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'remove': 0.60; 'reach': 0.63; 'received:50.22': 0.84; 'dirty': 0.93 Date: Sat, 15 Mar 2014 21:58:45 -0500 From: Tim Chase To: python-list@python.org Subject: Clearing out handlers in logging? X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394938715 news.xs4all.nl 2874 [2001:888:2000:d::a6]:58276 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68379 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