Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news.osn.de!diablo2.news.osn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '16,': 0.03; 'handler': 0.05; 'think,': 0.07; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handler,': 0.16; 'handlers.': 0.16; 'inability': 0.16; 'somewhere.': 0.16; 'subject:Clearing': 0.16; 'suggestion.': 0.16; "tim's": 0.16; 'wrote:': 0.18; 'written': 0.21; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '>>>>': 0.31; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'tasks': 0.38; 'pm,': 0.38; 'little': 0.38; 'sure': 0.39; 'remove': 0.60; 'read': 0.60; 'reaching': 0.61; 'reach': 0.63; 'mar': 0.68; 'implications': 0.84; 'safer': 0.84; 'viable': 0.84; 'to:none': 0.92; 'dirty': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=7VYjfdX6nR4y6EUyto+o6IqYC4iY7cGhT+dHkoUOmcg=; b=Ssko9XrzHUYGaImg4sL01KkfN42nt/Otct3OeH9ny0bgFJaQ3uKbA+PSaU+aHB2LeR BP/JMJxv70TCsUaXliHW2wGwqkU+rEbIJ6fmaBE9k6KnTVVlY5sVRL6797WO7gfAK3cu d1Ss/8i1gWVBhU8mOAHqGXIsO9Yd4wHM18Xo1WFinCgp1B8uNUV2NYgqWuHtHo9ECCgQ OcBNyhlzcTDF/sQ2sjMEiPVZAMLTuiaLMt/2n20EV4VtI6YQaniGvzhD/mmekK5/qfCR Ri0FA9OGlNOE+8f1qW+SJXz0kj/GGMjLMpnistVuqOreIBRe/G2DzpXWgD6APEIe40mP Ib8Q== MIME-Version: 1.0 X-Received: by 10.66.232.7 with SMTP id tk7mr19301675pac.94.1394960577628; Sun, 16 Mar 2014 02:02:57 -0700 (PDT) In-Reply-To: References: Date: Sun, 16 Mar 2014 20:02:57 +1100 Subject: Re: Clearing out handlers in logging? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394960581 news.xs4all.nl 2892 [2001:888:2000:d::a6]:38480 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68388 On Sun, Mar 16, 2014 at 7:39 PM, Gunther Dietrich wrote: >>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. > > What about this: > >>>> for handler in log.handlers: > ... log.removeHandler(handler) > > I think, that's just one of the tasks that removeHandler() was written > for. I'm sure Tim was aware of the removeHandler function. But this is still reaching into log.handlers - although IMO it's safer to reach in and read than to reach in and mutate. So without the implications of Tim's inability to read docs, this is a viable suggestion. I'd prefer this over the original "del log.handlers[:]". ChrisA