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


Groups > comp.lang.python > #15775

Re: Got some problems when using logging Filter

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:using': 0.04; 'suppose': 0.05; 'prints': 0.07; 'subject:when': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:problems': 0.09; 'output': 0.10; 'skip:[ 20': 0.12; 'def': 0.14; 'this:': 0.15; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'subject:Filter': 0.16; 'subject:Got': 0.16; 'subject:logging': 0.16; 'wrote:': 0.18; 'from:addr:web.de': 0.23; 'import': 0.28; 'tried': 0.28; 'pass': 0.28; 'looks': 0.28; 'print': 0.29; 'class': 0.29; 'subject:some': 0.30; 'thanks': 0.31; 'to:addr:python-list': 0.32; 'source': 0.33; 'header:X-Complaints-To:1': 0.33; 'filter': 0.34; 'root': 0.34; 'skip:h 40': 0.34; 'cat': 0.36; 'received:org': 0.37; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'skip:l 20': 0.40; 'your': 0.61; 'applying': 0.62; 'demo': 0.80
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Got some problems when using logging Filter
Date Wed, 16 Nov 2011 15:50:51 +0100
Organization None
References <5b246f46-ca59-43a4-b9a6-29fdfc86822e@j19g2000pro.googlegroups.com> <mailman.2765.1321443604.27778.python-list@python.org> <b99b3c1d-9552-4c93-839d-d822cbcaca6a@g27g2000pre.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084beb4.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2768.1321455056.27778.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1321455056 news.xs4all.nl 6938 [2001:888:2000:d::a6]:37238
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15775

Show key headers only | View raw


sword wrote:

> Thanks for your reply. I tried to edit the source a bit, now the
> main.py looks like this:
> #main.py
> import logging
> from logging import Filter
> import a
> import b
> 
> logging.basicConfig(level=logging.DEBUG)
> root = logging.getLogger()
> root.addFilter(Filter("GoneWithTheWind")) #so I suppose no log msg
> would pass this filter
> 
> logger = logging.getLogger("main")
> logger.debug("main process")
> a.print_log()
> b.print_log()
> 
> ####
> And It still prints out all the log msg. :(

Here's a little demo to explore how filtering works:

$ cat demo.py
import logging
class Filter(logging.Filter):
    def filter(self, record):
        print "applying filter", self.name
        return True

logging.basicConfig()

loggers = [logging.getLogger(path) for path in ["", "a", "a.b"]]
for logger in loggers:
    logger.addFilter(Filter("filter@" + logger.name))

[handler] = logging.getLogger().handlers
handler.addFilter(Filter("filter@handler"))

for logger in loggers:
    logger.critical("whatever")
$ python demo.py
applying filter filter@root
applying filter filter@handler
CRITICAL:root:whatever
applying filter filter@a
applying filter filter@handler
CRITICAL:a:whatever
applying filter filter@a.b
applying filter filter@handler
CRITICAL:a.b:whatever
$

As you can infer from the output only the filter(s) of the original logger 
and of the handler(s) are applied.


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Got some problems when using logging Filter sword <john.37@gmail.com> - 2011-11-15 22:09 -0800
  Re: Got some problems when using logging Filter Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-11-16 12:40 +0100
    Re: Got some problems when using logging Filter sword <john.37@gmail.com> - 2011-11-16 04:31 -0800
      Re: Got some problems when using logging Filter Peter Otten <__peter__@web.de> - 2011-11-16 15:50 +0100
        Re: Got some problems when using logging Filter sword <john.37@gmail.com> - 2011-11-17 01:06 -0800
          Re: Got some problems when using logging Filter Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-11-19 16:42 -0800
            Re: Got some problems when using logging Filter sword <john.37@gmail.com> - 2011-11-20 23:15 -0800
              Re: Got some problems when using logging Filter Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-11-21 02:11 -0800
      Re: Got some problems when using logging Filter Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-11-21 12:39 +0100

csiph-web