[py-dev] py.log and multiple keywords

Grig Gheorghiu grig at gheorghiu.net
Mon Jun 20 17:59:12 CEST 2005


--- holger krekel <hpk at trillke.net> wrote:

> Hi Grig!
> 
>> [Grig]
>> I still haven't figured out what a practical application of the
>> current
>> semantics for multiple keywords would be -- can you give an
>> example?
> [holger]
> I have used it the following way so far: 
> 
>     # -- 'somefile.py': 
> 
>     import py
> 
>     log = py.log.Producer("somefile") 
>     py.log.setconsumer("somefile", None)  # route all logging to
> /dev/null 
> 
>     def dispatch(x): 
>         log.dispatch(x) 
> 
>     def send(host, arg): 
>         log.send(arg, "to", host) 
> 
>     # -- 'test_somefile.py' 
>     import py
> 
>     py.log.setconsumer("somefile", py.log.STDOUT)  # show more info
> for failing tests
>     py.log.setconsumer("somefile send", None)  # don't show
> dispatching, though
> 
>     ... 
>     # -- end files 
> 
> So not only can you come up with new ad-hoc categories but you 
> can have fine-grained view control from remote places.  You can for 
> example, have a different logging view from a main cmdline entrypoint
> than from the tests etc.pp.  In this view, the distinction between
> 'debug' and 'info' etc.pp. depends on the perspective and is 
> not a static property of the source code.
> 

OK, this makes sense now. I was already using the various severity
levels dynamically, via a configuration file, as I noted in a previous
post. But I wasn't sure how the multiple keywords come into play. Now I
get it. I'll chew on all this some more and I'll probably post a
message with how I ended up using py.log in my code.

Thanks,

Grig



More information about the Pytest-dev mailing list