Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68379

Clearing out handlers in logging?

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 <python.list@tim.thechases.com>
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 <python.list@tim.thechases.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8159.1394938715.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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