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


Groups > comp.lang.python > #68390

Re: Clearing out handlers in logging?

References <mailman.8159.1394938715.18130.python-list@python.org> <gd.usenet-B1805D.09394016032014@dwarf.main.lan> <lg3q8a$2p7$1@ger.gmane.org>
Date 2014-03-16 20:35 +1100
Subject Re: Clearing out handlers in logging?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8165.1394962522.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Mar 16, 2014 at 8:18 PM, Peter Otten <__peter__@web.de> wrote:
> Hm, what do the docs say about this one?
>
>>>> import logging
>>>> logging.basicConfig()
>>>> log = logging.getLogger("foo")
>>>> for i in range(5):
> ...     log.addHandler(logging.FileHandler("tmp.log"))
> ...
>>>> assert len(log.handlers) == 5
>>>> for handler in log.handlers:
> ...     log.removeHandler(handler)
> ...
>>>> log.handlers
> [<logging.FileHandler object at 0x7f8217686e90>, <logging.FileHandler object
> at 0x7f8216f9eb90>]

for handler in log.handlers[:]:
    log.removeHandler(handler)

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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