[py-dev] py.log suggestion

François Pinard pinard at iro.umontreal.ca
Sat Oct 15 02:46:03 CEST 2005


Hi, people.

I wrote to this list, a little while ago, about using py.log in some big
Python project I should seriously clean up, and which currently abuses
of various logging mechanisms.  I thought this job would induce me in
using quite a flurry of py.log producers.  Instead, for the past weeks,
I was more active at aggressively forever _removing_ amounts of logging
calls.  A lot still remain, for which py.log is going to be useful.

Today, I saw a situation of logging made in context of tracing the
hearth of one of the evaluation engines.  When such logging/tracing is
active, the application is going to be applied to a toy subset of the
real input.  Otherwise, logging would be triggered millions of times.
The problem is that log messages themselves require a fair amount of
extra-computation that would better be spared when tracing is not active
(which is most of the time).

My suggestion, here, is that producers, besides their ``__call__``
method, could also offer a ``__nonzero__`` method that would return
False when the consumer that would apply is None.  So, one could write
something like:

    if trace.dossier:
        diagnostic = prepare_diagnostic_information()
        trace.dossier(diagnostic)

It looks clean and lean to me to use the producer for the test as well
as for the call.  Do you share this opinion?

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Pytest-dev mailing list