[py-dev] py.log suggestion

François Pinard pinard at iro.umontreal.ca
Wed Oct 26 04:22:23 CEST 2005


[holger krekel]

> I see the use of being able to lazify interpolation but it puts the
> producer even further away from the print statement.  Also it's
> incompatible to current usage.  Currently

>     print x, "hello", z

> is mostly equivalent to

>     mylog(x, "hello", z)

> and somehow i'd like to keep it that way.

Oh!  I did not know that similarity with ``print``, which I always
perceived as a debugging statement -- I can blindly get rid of any
``print`` statements at any time in my programs).

No doubt I can tame myself to the above! :-)

>     mylog("hello %(x)s".__mod__ , x=3)

Hmph!  That's too clever to be really useful! :-).

> So, in short, i propose to treat the case of the first arg
> being a callable, simply as:

>     if consumer is not None:
>         if args and callable(args[0]):
>             args = args[0](*args[1:], **kwargs)
>             kwargs = None
>         ...

It surely solves the initial problem, anyway, which is to have some way
to conditionalise out semi-lengthy computations whose sole purpose is to
generate the text of log messages.

> (you could make the 'if' even a 'while' :-)
> what do you think?

Maybe, yet there is a slight danger that logging be less fun, if it was
requiring too much attention, and was a bit prone at creating looping
problems or other obscure bugs, that would distract users away from the
outside problems they are scrutinizing.  Or maybe I'm over-cautious,
it's not easy to predict where is the correct equilibrium.

And there is this unexpected danger as well, which you underlined in one
of your replies, and which I did not foresee (I should probably have),
that mylog may receive a first argument which is unexpectedly callable.
I hope it would not be much of a practical problem, and would feel ready
to take the risk and use it, just to acquire some experience about if it
creates practical problems, or not.

P.S. - Sorry for the delay in replying.  Job pressure is high in these
days!

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


More information about the py-dev mailing list