[py-dev] Logging in the py library

holger krekel hpk at trillke.net
Sun Jun 12 01:10:08 CEST 2005


On Sat, Jun 11, 2005 at 15:23 -0700, Grig Gheorghiu wrote:
> --- holger krekel <hpk at trillke.net> wrote:
> > On Sat, Jun 11, 2005 at 08:54 -0700, Grig Gheorghiu wrote:
> > > --- holger krekel <hpk at trillke.net> wrote:
> > Hum, coming to think of it you may need to tweak the __init__.py 
> > file definitions for the time being to something like: 
> > 
> >     'py.log.debug':  ('./misc/log.py', 'debug'), 
> >     'py.log.warn':   ('./misc/log.py', 'warn'), 
> > 
> >     'py.log.set_logger':  ('./misc/log.py', 'set_logger'), 
> >     'py.log.File':  ('./misc/log_support.py', 'File'), 
> > 
> I've been trying to unify the log and trace namespaces, but I'm kind of
> lost. When you have
> 
> 'py.log.debug':  ('./misc/log.py', 'debug'), 
> 
> in __init__.py, that means there needs to be an object called 'debug'
> in misc/log.py. How do you associate that object with a method of the
> class Tracer? I looked in other files, but all the objects I've seen
> that are exposed in __init__.py are either classes or instances of
> classes.

Sorry, if __init__.py's logic is a bit opaque.  Basically you could
do e.g. in trace.py at the end

    tracer = Tracer() 
    debug = tracer.debug 
    warn = tracer.warn 
    ... 

and then 

    'py.trace.debug':   ('./misc/trace.py', 'debug'), 

should work. The rule is simply that the 'debug' name is picked
from the module which needs to provide a name-object binding. 
There is no restriction on what type of object that could be. 
    
> Also, do you want to have both a Tracer class and a Logger class in
> log.py? It becomes kind of confusing if you're associating py.log.debug
> with a debug method of the class Tracer. Generally speaking, the
> distinction between Tracer and Logger will be kind of hard to grasp for
> somebody new to the py library -- at least that's my opinion...

You are probably right.   Maybe indeed use your suggested names 
py.log.Consumer and py.log.Producer?  So py.log.debug 
would be a Producer with the keyword 'debug'.  

> If you want to change the code and refactor the trace.py module by
> renaming it log.py and properly exposing the debug, warn, etc. objects
> in __init__.py, that would help me in understanding more accurately
> what you have in mind.

I can do that if you get stuck again (and don't consider 
this your fault, btw). 

cheers, 

    holger



More information about the Pytest-dev mailing list